springMVC支持restful服务写出的服务端^_^

之前不知道怎么实现,查了一大堆乱七八糟的,最后写出来的时候发现其实很简单。

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);
}

猜你喜欢

转载自blog.csdn.net/innerpeaceScorpio/article/details/50433065