- 浏览: 523698 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (422)
- 重要 (12)
- BUG解决备忘录 (32)
- 环境搭建 (17)
- 开源组件 (4)
- 数据库 (16)
- 设计模式 (4)
- 测试 (3)
- javascript (5)
- Android (14)
- jdk相关 (9)
- struts2 (10)
- freemark (3)
- 自定义扩展及工具类 (5)
- jdk5新特性及java基础 (13)
- ssh及其他框架 (15)
- linux (32)
- tcp-ip http协议 (8)
- 服务器集群与负载均衡 (34)
- 项目管理相关 (11)
- 实用小技术 (10)
- 架构相关 (14)
- firefox组件 (11)
- spider (6)
- 产品设计 (11)
- PHP (1)
- ws (4)
- lucene (10)
- 其他 (2)
- BI (1)
- NoSQL (3)
- gzip (1)
- ext (4)
- db (6)
- socket (1)
- 源码阅读 (2)
- NIO (2)
- 图片处理 (1)
- java 环境 (2)
- 项目管理 (4)
- 从程序员到项目经理(一):没有捷径 (1)
- bug (1)
- JAVA BASE (8)
- 技术原理 (0)
- 新框架新技术 (1)
- 量化与python (1)
- 系统编程 (0)
- C语言 (0)
- 汇编 (0)
- 算法 (0)
最新评论
-
hyspace:
别逗了,最后一个算法根本不是最优的,sort(function ...
数组去重——一道前端校招试题 -
washingtin:
楼主能把策略和路由的类代码贴出来吗
Spring + iBatis 的多库横向切分简易解决思路 -
sdyjmc:
初略看了一下,没有闹明白啊,均衡负载使用Nginx,sessi ...
J2EE集群原理 I -
shandeai520:
谢谢大神!请教大神一个问题:假如我有三台服务器,连接池的上限是 ...
集群和数据库负载均衡的研究 -
hekuilove:
给lz推荐一下apache commonsStringUtil ...
request 获取 ip
最近在研究spring3.0以及传说中的restful,还好研究出来一个例子,现在贴出来望广大网友能一起讨论下,错误的地方恳请大家指点。项目采用SPRING3.0+HIBERNATE2.5。数据库是oracle只有一个表。
[java]
view plain
copy
- create table LMDZ
- (
- KH_NUM VARCHAR2(20 ),
- LM_NUM NUMBER(2 )
- );
首先在eclipse下新建web工程。web.xml文件配置如下:
[java]
view plain
copy
- <?xml version= "1.0" encoding= "UTF-8" ?>
- <web-app version="2.5" xmlns= "http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
- <!--
- 该servlet为tomcat,jetty等容器提供,将静态资源映射从/改为/static /目录,如原来访问
- http://localhost/foo.css ,现在http://localhost/static/foo.css
- -->
- <servlet-mapping>
- <servlet-name>default </servlet-name>
- <url-pattern>/static /*</url-pattern>
- </servlet-mapping>
- <servlet>
- <servlet-name>demorestsms</servlet-name>
- <servlet-class >org.springframework.web.servlet.DispatcherServlet</servlet- class >
- <load-on-startup>1 </load-on-startup>
- </servlet>
- <!--
- Key of the system property that should specify the root directory of this
- web app. Applied by WebAppRootListener or Log4jConfigListener.
- -->
- <context-param>
- <param-name>webAppRootKey</param-name>
- <param-value>demorestsms.root</param-value>
- </context-param>
- <!--
- Location of the Log4J config file, for initialization and refresh checks.
- Applied by Log4jConfigListener.
- -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>/WEB-INF/classes/log4j.properties</param-value>
- </context-param>
- <!--
- - Location of the XML file that defines the root application context.
- - Applied by ContextLoaderServlet.
- -
- - Can be set to:
- - "/WEB-INF/applicationContext-hibernate.xml" for the Hibernate implementation,
- - "/WEB-INF/applicationContext-jpa.xml" for the JPA one, or
- - "/WEB-INF/applicationContext-jdbc.xml" for the JDBC one.
- -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml</param-value>
- <!--
- <param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
- <param-value>/WEB-INF/applicationContext-jpa.xml</param-value>
- -->
- <!--
- To use the JPA variant above, you will need to enable Spring load-time
- weaving in your server environment. See PetClinic's readme and/or
- Spring's JPA documentation for information on how to do this .
- -->
- </context-param>
- <!--
- - Configures Log4J for this web app.
- - As this context specifies a context-param "log4jConfigLocation" , its file path
- - is used to load the Log4J configuration, including periodic refresh checks.
- -
- - Would fall back to default Log4J initialization (non-refreshing) if no special
- - context-params are given.
- -
- - Exports a "web app root key" , i.e. a system property that specifies the root
- - directory of this web app, for usage in log file paths.
- - This web app specifies "petclinic.root" (see log4j.properties file).
- -->
- <!-- Leave the listener commented-out if using JBoss -->
- <!--
- <listener>
- <listener-class >org.springframework.web.util.Log4jConfigListener</listener- class >
- </listener>
- -->
- <!--
- - Loads the root application context of this web app at startup,
- - by default from "/WEB-INF/applicationContext.xml" .
- - Note that you need to fall back to Spring's ContextLoaderServlet for
- - J2EE servers that do not follow the Servlet 2.4 initialization order.
- -
- - Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- - to access it anywhere in the web application, outside of the framework.
- -
- - The root context is the parent of all servlet-specific contexts.
- - This means that its beans are automatically available in these child contexts,
- - both for getBean(name) calls and (external) bean references.
- -->
- <listener>
- <listener-class >org.springframework.web.context.ContextLoaderListener</listener- class >
- </listener>
- <!--
- - Maps the petclinic dispatcher to "*.do" . All handler mappings in
- - petclinic-servlet.xml will by default be applied to this subpath.
- - If a mapping isn't a /* subpath, the handler mappings are considered
- - relative to the web app root.
- -
- - NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
- -->
- <servlet-mapping>
- <servlet-name>zszqrestsms</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>10 </session-timeout>
- </session-config>
- <welcome-file-list>
- <!-- Redirects to "welcome.htm" for dispatcher handling -->
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <!--error-page>
- <exception-type>java.lang.Exception</exception-type>
- <location>/WEB-INF/jsp/uncaughtException.jsp</location>
- </error-page-->
- <!-- 浏览器不支持put,delete等method,由该filter将/blog?_method=delete转换为标准的http delete方法 -->
- <filter>
- <filter-name>HiddenHttpMethodFilter</filter-name>
- <filter-class >org.springframework.web.filter.HiddenHttpMethodFilter</filter- class >
- </filter>
- <filter-mapping>
- <filter-name>HiddenHttpMethodFilter</filter-name>
- <servlet-name>demorestsms</servlet-name>
- </filter-mapping>
- </web-app>
在WEB-INF下面的applicationContext.xml文件如下:
[java]
view plain
copy
- <?xml version= "1.0" encoding= "UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc= "http://www.springframework.org/schema/jdbc"
- xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/jdbc
- http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
- <bean id="propertyConfigurer"
- class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
- p:location="/WEB-INF/jdbc.properties" />
- <bean id="dataSource"
- class = "org.springframework.jdbc.datasource.DriverManagerDataSource"
- p:driverClassName="${jdbc.driverClassName}"
- p:url="${jdbc.url}"
- p:username="${jdbc.username}"
- p:password="${jdbc.password}" />
- <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
- <!-- Hibernate SessionFactory -->
- <bean id="sessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean"
- p:dataSource-ref="dataSource" p:mappingResources= "zszqlmdz.hbm.xml" >
- <property name="hibernateProperties" >
- <props>
- <prop key="hibernate.dialect" >${hibernate.dialect}</prop>
- <prop key="hibernate.show_sql" >${hibernate.show_sql}</prop>
- <prop key="hibernate.generate_statistics" >${hibernate.generate_statistics}</prop>
- </props>
- </property>
- <property name="eventListeners" >
- <map>
- <entry key="merge" >
- <bean class = "org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
- </entry>
- </map>
- </property>
- </bean>
- <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
- <bean id="transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager"
- p:sessionFactory-ref="sessionFactory" />
- <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
- <!--
- <bean id="transactionManager" class = "org.springframework.transaction.jta.JtaTransactionManager" />
- -->
- <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
- <!--
- Activates various annotations to be detected in bean classes:
- Spring's @Required and @Autowired, as well as JSR 250' s @Resource .
- -->
- <context:annotation-config/>
- <!--
- Instruct Spring to perform declarative transaction management
- automatically on annotated classes.
- -->
- <tx:annotation-driven/>
- <!--
- Exporter that exposes the Hibernate statistics service via JMX. Autodetects the
- service MBean, using its bean name as JMX object name.
- -->
- <context:mbean-export/>
- <!-- PetClinic's central data access object: Hibernate implementation -->
- <bean id="clinic" class = "com.cssweb.zszq.lmdz.hibernate.HibernateClinic" />
- <!-- Hibernate's JMX statistics service -->
- <bean name="demorestsms:type=HibernateStatistics" class = "org.hibernate.jmx.StatisticsService" autowire= "byName" />
- </beans>
在WEB-INF下面的demorestsms-servlet.xml文件如下:
[java]
view plain
copy
- <?xml version= "1.0" encoding= "UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p= "http://www.springframework.org/schema/p"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc= "http://www.springframework.org/schema/jdbc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/jdbc
- http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
- <!--
- - The controllers are autodetected POJOs labeled with the @Controller annotation.
- -->
- <context:component-scan base-package = "com.cssweb.zszq.lmdz.web" />
- <!--
- - The form-based controllers within this application provide @RequestMapping
- - annotations at the type level for path mapping URLs and @RequestMapping
- - at the method level for request type mappings (e.g., GET and POST).
- - In contrast, ClinicController - which is not form-based - provides
- - @RequestMapping only at the method level for path mapping URLs.
- -
- - DefaultAnnotationHandlerMapping is driven by these annotations and is
- - enabled by default with Java 5 +.
- -->
- <bean class = "org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
- <!--
- - This bean processes annotated handler methods, applying PetClinic-specific PropertyEditors
- - for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
- -->
- <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
- <property name="webBindingInitializer" >
- <bean class = "com.cssweb.zszq.lmdz.web.ClinicBindingInitializer" />
- </property>
- </bean>
- <!--
- - This bean resolves specific types of exceptions to corresponding logical
- - view names for error views. The default behaviour of DispatcherServlet
- - is to propagate all exceptions to the servlet container: this will happen
- - here with all other types of exceptions.
- -->
- <bean class = "org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
- <property name="exceptionMappings" >
- <props>
- <prop key="org.springframework.dao.DataAccessException" >dataAccessFailure</prop>
- <prop key="org.springframework.transaction.TransactionException" >dataAccessFailure</prop>
- </props>
- </property>
- </bean>
- <!--
- - This bean configures the 'prefix' and 'suffix' properties of
- - InternalResourceViewResolver, which resolves logical view names
- - returned by Controllers. For example, a logical view name of "vets"
- - will be mapped to "/WEB-INF/jsp/vets.jsp" .
- -->
- <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix= "/WEB-INF/jsp/"
- p:suffix=".jsp" />
- <!--
- - Message source for this context, loaded from localized "messages_xx" files.
- - Could also reside in the root application context, as it is generic,
- - but is currently just used within PetClinic's web tier.
- -->
- <bean id="messageSource" class = "org.springframework.context.support.ResourceBundleMessageSource"
- p:basename="messages" />
- </beans>
在WEB-INF下面的jdbc.properties文件如下:
[java]
view plain
copy
- # To change this template, choose Tools | Templates
- # and open the template in the editor.
- jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
- jdbc.url=jdbc:oracle:thin:@localhost : 1521 :orcl
- jdbc.username=scott
- jdbc.password=tiger
- hibernate.generate_statistics=true
- hibernate.show_sql=true
- hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
配置大致就这些,下面给出连接hibernate的接口
[java]
view plain
copy
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.cssweb.zszq.lmdz;
- import java.util.Collection;
- import org.springframework.dao.DataAccessException;
- import com.cssweb.zszq.lmdz.pojo.Khzl;
- import com.cssweb.zszq.lmdz.pojo.LmdzNew;
- /**
- *
- * @author HUJUN
- */
- public interface Clinic {
- Collection<LmdzNew> findLmdzs(String fundid) throws DataAccessException;
- void save(String fundid, String[] no) throws DataAccessException;
- int delete(String fundid) throws DataAccessException;
- Khzl findKh(String clientId) throws DataAccessException;
- int updateTelById(String fundid, String mobile) throws DataAccessException;
- }
连接hibernate的service类
[java]
view plain
copy
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.cssweb.zszq.lmdz.hibernate;
- import java.util.Collection;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import com.cssweb.zszq.lmdz.Clinic;
- import com.cssweb.zszq.lmdz.pojo.Khzl;
- import com.cssweb.zszq.lmdz.pojo.LmdzNew;
- /**
- *
- * @author HUJUN
- */
- public class HibernateClinic implements Clinic {
- @Autowired
- private SessionFactory sessionFactory;
- @Transactional (readOnly = true )
- @SuppressWarnings ( "unchecked" )
- public Collection<LmdzNew> findLmdzs(String fundid) {
- return sessionFactory.getCurrentSession().createQuery( "from LmdzNew lmdz where lmdz.khNum = :fundid" )
- .setString("fundid" , fundid).list();
- }
- public void save(String fundid, String[] no) {
- Session session = sessionFactory.openSession();
- Transaction tx = session.beginTransaction();
- for ( int i = 0 ; i < no.length; i++) {
- LmdzNew lmdzNes = new LmdzNew(fundid, Integer.parseInt(no[i]));
- session.save(lmdzNes);
- if (i % 20 == 0 ) {
- session.flush();
- session.clear();
- }
- }
- tx.commit();
- session.close();
- }
- public int delete(String fundid) {
- return sessionFactory.openSession().createQuery( "delete from LmdzNew lmdz where lmdz.khNum = :fundid" )
- .setString("fundid" , fundid).executeUpdate();
- }
- @Transactional (readOnly = true )
- public Khzl findKh(String clientId) {
- return (Khzl) sessionFactory.openSession().load(Khzl. class , clientId);
- }
- public int updateTelById(String fundid, String mobile) {
- return sessionFactory.openSession().createQuery( "update Khzl set mobileTel = :mobile where clientId = :fundid" )
- .setString("fundid" , fundid)
- .setString("mobile" , mobile)
- .executeUpdate();
- }
- }
再来看action这一层的东西:
[java]
view plain
copy
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.cssweb.zszq.lmdz.web;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.util.Collection;
- import java.util.Iterator;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import com.cssweb.common.util.CollectionData;
- import com.cssweb.zszq.lmdz.Clinic;
- import com.cssweb.zszq.lmdz.pojo.Khzl;
- import com.cssweb.zszq.lmdz.pojo.LmdzNew;
- /**
- *
- * @author HUJUN
- */
- @Controller
- @RequestMapping ( "/zszqsms" )
- public class LmdzForm {
- private final Clinic clinic;
- @Autowired
- public LmdzForm(Clinic clinic) {
- this .clinic = clinic;
- }
- @RequestMapping (value= "/{fundid}" , method = RequestMethod.GET)
- public void get(HttpServletRequest request, HttpServletResponse response, @PathVariable ( "fundid" ) String fundid) throws Exception {
- System.out.println(">>>>>>>>>>getList>>>>>>>>>>>>>>" +fundid);
- StringBuilder msg = new StringBuilder();
- Khzl khzl = this .clinic.findKh(fundid);
- if (khzl!= null ) {
- Collection<LmdzNew> lm = CollectionData.getLmList();
- Collection<LmdzNew> results = this .clinic.findLmdzs(fundid);
- Iterator<LmdzNew> it = lm.iterator();
- String json = "{total:" +lm.size()+ ",root:[" ;
- int i = 0 ;
- while (it.hasNext()) {
- LmdzNew lmdz = it.next();
- lmdz.setState(1 );
- json += "{lmid:'" + lmdz.getLmNum() + "',lmname:'" + lmdz.getLmName() + "',lmstate:'" + lmdz.getState() + "'}" ;
- i++;
- if (i != lm.size() - 1 ) {
- json += "," ;
- }
- }
- json += "]}" ;
- msg.append("{/" msg/ ":/" "+json+" / "}" );
- }
- else {
- msg.append("{/" msg/ ":/" 帐号不存在/ "}" );
- }
- printData(response, msg);
- }
- @RequestMapping (value = "/{fundid}/{no}" , method = RequestMethod.POST)
- public void save(HttpServletRequest request, HttpServletResponse response, @PathVariable ( "fundid" ) String fundid,
- @PathVariable ( "no" ) String no) throws Exception {
- System.out.println(fundid + ">>>>>>>>>>save>>>>>>>>>>>>>>" +no);
- StringBuilder msg = new StringBuilder();
- this .clinic.save(fundid, no.split( "," ));
- msg.append("{/" msg/ ":/" 成功/ "}" );
- printData(response, msg);
- }
- @RequestMapping (value = "/{fundid}/{no}" , method = RequestMethod.PUT)
- public void update(HttpServletRequest request, HttpServletResponse response, @PathVariable ( "fundid" ) String fundid,
- @PathVariable ( "no" ) String no) throws Exception {
- System.out.println(fundid + ">>>>>>>>>>update>>>>>>>>>>>>>>" +no);
- StringBuilder msg = new StringBuilder();
- int i = this .clinic.updateTelById(fundid, no);
- if (i> 0 ) {
- msg.append("{/" msg/ ":/" 成功/ "}" );
- }
- msg.append("{/" msg/ ":/" 失败/ "}" );
- printData(response, msg);
- }
- @RequestMapping (value = "/{fundid}" , method = RequestMethod.DELETE)
- public void delete(HttpServletRequest request, HttpServletResponse response, @PathVariable ( "fundid" ) String fundid)
- throws Exception {
- System.out.println(">>>>>>>>>>delete>>>>>>>>>>>>>>" +fundid);
- StringBuilder msg = new StringBuilder();
- int i = this .clinic.delete(fundid);
- if (i> 0 ) {
- msg.append("{/" msg/ ":/" 成功/ "}" );
- }
- msg.append("{/" msg/ ":/" 失败/ "}" );
- printData(response, msg);
- }
- private void printData(HttpServletResponse response, StringBuilder msg){
- try {
- response.setContentType("text/html;charset=utf-8" );
- response.setCharacterEncoding("UTF-8" );
- PrintWriter out = new PrintWriter( new OutputStreamWriter(response.getOutputStream(), "UTF-8" ));
- out.println( msg );
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
最后还有个POJO类,呵呵:
[java]
view plain
copy
- package com.cssweb.zszq.lmdz.pojo;
- /**
- * LmdzNew entity. @author MyEclipse Persistence Tools
- */
- public class LmdzNew implements java.io.Serializable {
- // Fields
- /**
- *
- */
- private static final long serialVersionUID = -5138845755309588033L;
- private String khNum;
- private int lmNum;
- private String lmName;
- private int state;
- // Constructors
- /** default constructor */
- public LmdzNew() {
- }
- /** full constructor */
- public LmdzNew(String khNum, int lmNum) {
- this .khNum = khNum;
- this .lmNum = lmNum;
- }
- public String getKhNum() {
- return this .khNum;
- }
- public void setKhNum(String khNum) {
- this .khNum = khNum;
- }
- public int getLmNum() {
- return this .lmNum;
- }
- public void setLmNum( int lmNum) {
- this .lmNum = lmNum;
- }
- public String getLmName() {
- return lmName;
- }
- public void setLmName(String lmName) {
- this .lmName = lmName;
- }
- public int getState() {
- return state;
- }
- public void setState( int state) {
- this .state = state;
- }
- public boolean equals(Object other) {
- if (( this == other))
- return true ;
- if ((other == null ))
- return false ;
- return false ;
- }
- public int hashCode() {
- int result = 17 ;
- result = 37 * result
- + (getKhNum() == null ? 0 : this .getKhNum().hashCode());
- return result;
- }
- }
好了,所有的源代码都贴出来了。整个服务端的程序可以跑在tomcat下做测试。接下来我们只需要提供rest客户端的接口让别的应用调用即可。下面再给出个调用的demo。这个项目比较简单。
还望大家多多指教,大家互相学习学习。
[java]
view plain
copy
- package com.cssweb.zszq.client;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class ClientTest {
- public static void main(String[] args) throws IOException {
- delete();
- update();
- save();
- select();
- }
- /**
- * 查询栏目定制
- * 68008610为资金帐号
- */
- public static void select() {
- try {
- URL url = new URL( "http://localhost:8080/zszqrestsms/zszqsms/68008610" );
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setDoOutput(true );
- conn.setRequestMethod("GET" );
- conn.setRequestProperty("Content-Type" , "text/json" );
- BufferedReader rd = new BufferedReader( new InputStreamReader(conn
- .getInputStream()));
- String line;
- while ((line = rd.readLine()) != null ) {
- System.out.println(line);
- }
- rd.close();
- } catch (Exception e) {
- System.out.println("Error" + e);
- }
- }
- /**
- * 删除定制栏目
- * 68008610为资金帐号
- */
- public static void delete() {
- try {
- URL url = new URL( "http://localhost:8080/zszqrestsms/zszqsms/68008610" );
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setDoOutput(true );
- conn.setRequestMethod("DELETE" );
- conn.setRequestProperty("Content-Type" , "text/json" );
- BufferedReader rd = new BufferedReader( new InputStreamReader(conn
- .getInputStream()));
- String line;
- while ((line = rd.readLine()) != null ) {
- System.out.println(line);
- }
- rd.close();
- } catch (Exception e) {
- System.out.println("Error" + e);
- }
- }
- /**
- * 修改手机号码
- * 68008610为资金帐号
- */
- public static void update() {
- try {
- URL url = new URL( "http://localhost:8080/zszqrestsms/zszqsms/68008610/1342345677" );
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setDoOutput(true );
- conn.setRequestMethod("PUT" );
- conn.setRequestProperty("Content-Type" , "text/json" );
- BufferedReader rd = new BufferedReader( new InputStreamReader(conn
- .getInputStream()));
- String line;
- while ((line = rd.readLine()) != null ) {
- System.out.println(line);
- }
- rd.close();
- } catch (Exception e) {
- System.out.println("Error" + e);
- }
- }
- /**
- * 保存定制的栏目
- * 68008610为资金帐号
- */
- public static void save() {
- try {
- URL url = new URL( "http://localhost:8080/zszqrestsms/zszqsms/68008617/1,2,3,4" );
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setDoOutput(true );
- conn.setRequestMethod("POST" );
- conn.setRequestProperty("Content-Type" , "text/json" );
- BufferedReader rd = new BufferedReader( new InputStreamReader(conn
- .getInputStream()));
- String line;
- while ((line = rd.readLine()) != null ) {
- System.out.println(line);
- }
- rd.close();
- } catch (Exception e) {
- System.out.println("Error" + e);
- }
- }
- }
发表评论
-
求鱼不如求渔 Welcome to MICKY's HOME Spring中加载ApplicationContext.xml文件的方式【转
2013-03-08 10:43 8381.利用ClassPathXmlApplication ... -
小试Bean Validation
2012-03-18 21:56 867数据校验是任何一个应用程序都会用到的功能,无论是显示层还是持久 ... -
Hibernate-Validation的使用
2012-03-18 11:56 1458以前弄过hibernate-validation的,可今天 ... -
springMVC3 基于注解的输入验证
2012-03-18 00:51 1617在pom.xml中加入,他需要validation-api ... -
Spring REST
2012-03-16 11:40 1194前面介绍过Spring的MVC结合不同的view显示不同的 ... -
设计 REST 风格的 MVC 框架
2012-03-16 11:38 955简介: 传统的 JavaEE MVC 框架如 Struts ... -
Spring mvc 构造RESTful URL 详细讲解(spring 3.0 应用)
2012-03-16 11:34 2337详细讲解spring rest使用,简单例子如下: / ... -
Spring MVC REST 例子
2012-03-16 03:17 1236package com.benx; ... -
ibatis存储过程调用(转载)
2011-08-14 17:11 11021 ibatis 调用oracle函数示例 2 ... -
通通透透理解ThreadLocal
2011-02-23 18:06 737概述 我们知道Spring通过各种DAO模板类降低了开发者使 ... -
乐观锁与悲观锁
2011-02-23 17:49 872文章转自网上好像是玉米田的,忘记了锁( locking ) 业 ... -
spring 依赖注入到直接new 对象
2010-09-16 15:50 1018当为遗留系统加入spring时,经典问题就是遗留系统需要引用s ... -
Spring注解入门
2010-06-03 17:11 8431. 使用Spring注解来注入属性 1.1. 使用注解 ... -
Spring2.0用注解实现事务管理
2010-06-03 15:50 903Spring2.0 框架的事务处理有两大类: 1 ...
相关推荐
Spring 3.0版本是其发展史上的一个重要里程碑,引入了许多新特性,提升了性能和易用性。Spring Security是Spring框架的一个子项目,专注于应用安全,提供了全面的身份验证、授权和访问控制解决方案。 Spring ...
一个很不错的实战指南,你值得拥有。 PS:适合初学者,知其然不知其所以然的码农。
标题 "spring2.5+struts2+hibernate3.0JAR包集合" 提及的是一个集成开发环境中的核心组件,这三个框架是Java Web开发中的重要工具,用于构建高效、可扩展的企业级应用程序。 Spring 2.5是Spring框架的一个版本,它...
它提供了一个统一的编程模型,支持多种Redis操作,包括但不限于键操作、字符串、哈希、列表、集合和有序集合等。通过Spring Data Redis,开发者可以利用Spring的依赖注入(DI)和声明式事务管理等特性,实现更高级别...
标题中的“Spring对JDBC和ORM的支持”是一个关键主题,涉及到Spring框架在数据库操作方面的核心功能。Spring是一个广泛使用的Java企业级应用开发框架,它提供了一整套工具和功能来简化JDBC(Java Database ...
9. **RESTful API支持**: 改进了`@RequestMapping`的处理,使其支持更多HTTP方法,如PUT、DELETE等,更便于构建RESTful API。 10. **测试增强**: Spring MVC Test框架提供了更好的测试支持,可以进行模拟请求和...
在Spring 2.5和3.0之间的主要区别在于配置方式的简洁性和灵活性,以及对注解支持的增强。随着版本的更新,Spring提供了更现代和易于使用的API,使得定时任务的配置和管理更加高效。但无论在哪一版本,理解这些基本...
mybatis+pring+springmvc+mysql的所有包的整合jar包其中有spring-webmvc-3.2.0.RELEASE.jar和spring-core-3.2.0.RELEASE.jar以及mybatis-3.2.7.jar,junit-4.9.jar,mysql-connector-java-5.1.7-bin.jar等31个jar包
Spring4版本尤其注重性能提升、API优化以及对新技术的支持。下面,我们将深入解析这份文档中所涵盖的核心知识点。 1. **Java 8支持**: Spring4全面支持Java 8,包括Lambda表达式、新的日期与时间API等。这使得...
Spring Bean的初始化和销毁实例详解 Spring Bean的初始化和销毁是Spring框架中一个非常重要的概念,它们都是Bean生命周期中不可或缺的一部分。在Spring框架中,我们可以使用多种方式来控制Bean的初始化和销毁,以下...
Spring 4进一步优化了对RESTful服务的支持,提供了`@RestController`注解,将传统的`@Controller`与`@ResponseBody`结合,简化了REST服务的定义。此外,`@ExceptionHandler`注解可以帮助处理全局异常,提高代码的可...
Spring 4还强化了对RESTful服务的支持。通过使用@CrossOrigin注解,开发者可以轻松地处理跨域资源共享(CORS)问题,这对于构建Web服务尤其有用。此外,@RequestMapping的改进使得URL映射更加灵活,可以更好地处理...
很抱歉,根据您提供的信息,"pring初探共18页.pdf.zip" 和 "pring初探共18页.pdf." 看起来像是一个关于Spring框架的教程文档,但是具体的文件列表只提到了 "赚钱项目",这与Spring框架的学习内容不直接相关。...
Pring所著的《投资心理学解释》就是这一领域的重要读物,它不仅为读者提供了丰富的经典策略,还探讨了如何在市场中保持独立思考和理性决策。该书的CMT(特许市场技术分析师)认证阅读材料标签表明,这本书也常作为...
6. **多租户**:一个Elasticsearch实例可以支持多个索引,每个索引有自己的设置和映射,实现资源隔离。 **Elasticsearch 7.17.10的新特性和改进:** 1. **性能优化**:此版本可能包含了针对查询速度、索引速度以及...
这个项目提供了一个实际的平台,让开发者学习如何在Java环境中使用Spring Boot构建安全、高效的RESTful API,为密码管理应用提供后端支持。通过这个练习,开发者可以提升其对Spring Boot、RESTful API设计、数据安全...
【标签】:“pring事务共9页.pdf.z”这个标签可能是由于输入错误,但可以推断出主题仍然围绕Spring事务。标签中的".z"可能是指压缩文件的后缀,不过常见的压缩格式是.zip,这里可能是用户的误写或者特殊格式。 ...