pinkshining
2016-08-18 15:18:13
原
spring mvc+Resteasy+Mybatis+Ehcache整合开发java webservice接口示例demo
最近要做关于移动app的web服务接口调用项目,之前没做过类似的项目,故找资料整合了springmvc+Resteasy+Mybatis+Ehcache做了一个小demo,为之后的开发奠基。
开发环境eclipse+svn+maven+mysql
项目结构图:
其中webservice接口代码:
@Controller @Path("/companyws") public class CompanyWS { @Autowired CompanyService companyService; @GET @Produces(MediaType.TEXT_HTML) @Path("/index") public ModelAndView viewAll() { return new ModelAndView("index"); } @GET @Path("/ehcache") public String getCurrentTimeMillis(@QueryParam("param")String param){ return companyService.getCurrentTimeMillis(param); } @POST @Path("/login") public String login(@FormParam("username")String username,@FormParam("password")String password){ System.out.println("-----webservice company login-----"); String seed = companyService.login(username, password); String token = companyService.getCacheToken(seed); System.out.println(seed); System.out.println(token); return seed; } @POST @Path("/getCacheToken") public String getCacheToken(@FormParam("seed")String seed){ System.out.println("-----webservice company login-----"); return companyService.getCacheToken(seed); } @GET @Path("/count") public String count(@Context HttpServletRequest request){ System.out.println("-----webservice company count-----"); System.out.println(companyService.total()); return "company"; } /** * resteasy返回响应文件,在produces里可以写("*//*")可以表示任意文件,使用@context注解获取response" **/ @Path("/getAttach/{ID}") @GET @Produces("*/*") public ServerResponse getAttach(@PathParam("ID") String ID,@Context HttpServletResponse response){ Long requestTime = System.currentTimeMillis(); OutputStream outputStream = null; ServerResponse sr = null; byte[] data = null; try { outputStream = response.getOutputStream(); data = "dhcdslkcd".getBytes(); outputStream.write(data); outputStream.flush(); outputStream.close(); } catch (EOFException e) { e.printStackTrace(); //sr = new ServerResponse(e.getMessage(), e.getExceptionCode()); }catch (Exception e) { e.printStackTrace(); //sr = new ServerResponse(e.getMessage(), ExceptionCode.DBPROXY_OTHER); } return sr; } }
部署项目到tomcat服务器上,在浏览器输入http://localhost:8080/springmvcResteasyMybatisEhcache/companyws/count,结果如图所示:
具体的代码如下:
猜你喜欢
- 基于浏览器首选语言的springmvc和freemarker国际化配置的实现
- 基于maven与springMVC的拦截器Interceptor,控制器Controller的使用
- springmvc @RequestMapping注解的入门配置教程
- SpringMVC的三种统一异常处理实例代码分享
- bootstrap jquery underscore backbone 新浪微博 springmvc整合demo代码
- spring mvc-showcase,便于学习springmvc,maven工程,建议使用谷歌浏览器
- springmvc @RequestMapping注解伪静态技术
- springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载
- SpringMVC整合Redis demo小例子
- java Web SpringMVC项目实现12306余票查询功能
- springmvc开发微信公众平台验证token接口教程及其java源代码分享
- SpringMvc整合Mybatis搭建java Web入门项目实例,是基于MAVEN的java web工程
请下载代码后再发表评论
文件名:springmvcResteasyMybatisEhcache.zip,文件大小:117.803K
下载
- /
- /springmvcResteasyMybatisEhcache
- /springmvcResteasyMybatisEhcache/.classpath
- /springmvcResteasyMybatisEhcache/.project
- /springmvcResteasyMybatisEhcache/.settings
- /springmvcResteasyMybatisEhcache/.settings/.jsdtscope
- /springmvcResteasyMybatisEhcache/.settings/org.eclipse.jdt.core.prefs
- /springmvcResteasyMybatisEhcache/.settings/org.eclipse.m2e.core.prefs
- /springmvcResteasyMybatisEhcache/.settings/org.eclipse.wst.common.component
- /springmvcResteasyMybatisEhcache/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
- /springmvcResteasyMybatisEhcache/.settings/org.eclipse.wst.common.project.facet.core.xml
- /springmvcResteasyMybatisEhcache/src
- /springmvcResteasyMybatisEhcache/src/main
- /springmvcResteasyMybatisEhcache/src/main/java
- /springmvcResteasyMybatisEhcache/src/main/java/com
- /springmvcResteasyMybatisEhcache/src/main/java/com/uniware
- /springmvcResteasyMybatisEhcache/src/main/java/com/uniware/domain
- /springmvcResteasyMybatisEhcache/src/main/java/com/uniware/encry
- /springmvcResteasyMybatisEhcache/src/main/java/com/uniware/encry/util
- /springmvcResteasyMybatisEhcache/src/main/java/com/uniware
- /springmvcResteasyMybatisEhcache/src/main/java/com
- /springmvcResteasyMybatisEhcache/src/main/java
- /springmvcResteasyMybatisEhcache/src/main
- /springmvcResteasyMybatisEhcache
相关代码
- SpringCXF实现c#调用java webservice
- java webservice xfire实例入门学习教程
- 原 CXF的webservice,web版和java版
- 原 windows下使用cmd命令提示符生成java webservice客户端代码
- 原 Spring整合apache CXF发布RESTfull风格的java WebService接口
- Java WebService + Axis2开发实例
- java webservice实例教程
- 原 axis2 webservice实现文件上传删除功能
- 原 java使用axis框架开发webservice入门教程实例代码下载
- 原精 Java调用WebService接口实现发送手机短信验证码功能
- 原证 SpringBoot WebService (CXF)简单入门实例
- 原 java WebService技术开发简单用户登录案例,适合初学者学习eclipse开发java webservice
最近下载