springMVC支持restful服务写出的服务端^_^
2015-12-30 10:49
751 查看
之前不知道怎么实现,查了一大堆乱七八糟的,最后写出来的时候发现其实很简单。
restful就是一种架构风格,在springmvc中已经支持了这种架构风格。话不多说,直接把自己的代码贴上,暂时只用到了GET和POST,还没有用到PUT、DELETE,有时间再继续。
@Controller
@RequestMapping("/srlog")
public class RestConstroller {
public RestConstroller() {}
/**
*
* @param id
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/querytest/{id}", method=RequestMethod.GET)
@ResponseBody
public FlowLogData testMethod(@PathVariable("id") String id, HttpServletRequest request,
HttpServletResponse response){
FlowLogData data = new FlowLogData();
data=FlowBusiness.QueryFlowInfo(id, null, null);
return data;
}
/**
* 查询
*
* @param params
* String p_serialId,String p_flowBusinessType,String p_flowBusinessId
* @return 返回json格式数据
*
*/
@RequestMapping(value = "/queryFlow", method = RequestMethod.POST)
@ResponseBody
public FlowLogData QueryFlowLogInfo(@RequestBody FlowLogData p_flowLogData ,
HttpServletRequest request , HttpServletResponse response) {
FlowLogData data = new FlowLogData();
String serialId = p_flowLogData.getSerialId();
String flowBusinessType = p_flowLogData.getFlowBusinessType();
String flowBusinessId = p_flowLogData.getFlowBusinessId();
data = FlowBusiness.QueryFlowInfo(serialId, flowBusinessType, flowBusinessId);
return data;
}
/**
* 存储
*
* @param p_dataLogData
*/
@RequestMapping(value = "/logData", method = RequestMethod.POST)
public void LogDataInfo(@RequestBody DataLogData p_dataLogData ,
HttpServletRequest request , HttpServletResponse response) {
System.out.println("p_dataLogData.getClient() :" + p_dataLogData.getClient().toString());
DataBusiness.LogDataInfo(p_dataLogData);
}
restful就是一种架构风格,在springmvc中已经支持了这种架构风格。话不多说,直接把自己的代码贴上,暂时只用到了GET和POST,还没有用到PUT、DELETE,有时间再继续。
@Controller
@RequestMapping("/srlog")
public class RestConstroller {
public RestConstroller() {}
/**
*
* @param id
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/querytest/{id}", method=RequestMethod.GET)
@ResponseBody
public FlowLogData testMethod(@PathVariable("id") String id, HttpServletRequest request,
HttpServletResponse response){
FlowLogData data = new FlowLogData();
data=FlowBusiness.QueryFlowInfo(id, null, null);
return data;
}
/**
* 查询
*
* @param params
* String p_serialId,String p_flowBusinessType,String p_flowBusinessId
* @return 返回json格式数据
*
*/
@RequestMapping(value = "/queryFlow", method = RequestMethod.POST)
@ResponseBody
public FlowLogData QueryFlowLogInfo(@RequestBody FlowLogData p_flowLogData ,
HttpServletRequest request , HttpServletResponse response) {
FlowLogData data = new FlowLogData();
String serialId = p_flowLogData.getSerialId();
String flowBusinessType = p_flowLogData.getFlowBusinessType();
String flowBusinessId = p_flowLogData.getFlowBusinessId();
data = FlowBusiness.QueryFlowInfo(serialId, flowBusinessType, flowBusinessId);
return data;
}
/**
* 存储
*
* @param p_dataLogData
*/
@RequestMapping(value = "/logData", method = RequestMethod.POST)
public void LogDataInfo(@RequestBody DataLogData p_dataLogData ,
HttpServletRequest request , HttpServletResponse response) {
System.out.println("p_dataLogData.getClient() :" + p_dataLogData.getClient().toString());
DataBusiness.LogDataInfo(p_dataLogData);
}
相关文章推荐
- Restful传递数组参数及注解大全
- SpringMVC restful 注解之@RequestBody进行json与object转换
- PHP实现自动识别Restful API的返回内容类型
- python模块restful使用方法实例
- 极简的Restful框架推荐->Resty(服务端+客户端)
- PHP实现Restful风格的API
- 理解HTTP幂等性
- Spring整合Dwr,Cannot locate BeanDefinitionParser for element [annotation-scan]
- spring3 MVC手工搭建Spring3项目demo
- spring mvc 开发需要的jar包的用途详解
- 基于注解的 Spring MVC 简单入门-网摘
- [MVC] 深入浅出Spring MVC
- DICOM医学图像处理:Orthanc Plugin SDK实现WADO服务
- Apache CXF 和 Spring 开发RESTful Web Service 2
- spring mvc restful + json 测试代码(一)
- 分享一个基于 Node.js 的 Web 开发框架 - Nokitjs
- CXF+Spring+REST发布webservice服务
- Spring MVC 为例,从前台—>后台—>前台的编解码过程及出现乱码的案例
- (struts2) spring mvc + mybatis + maven整合
- 使用Spring MVC 4构建Restful服务