春天宁静的网络服务岗位方法

时间:2014-02-01 18:41:26

标签: spring rest post

感谢您的时间。

我已经编写了spring restfull webservice来处理我的spring控制器类中的post方法,而我正在使用SOAP UI和RestClient进行测试,我得到“415 post method not available”消息。

@RequestMapping(value = "/insertperfinfo)
public class SessionInfoController implements Controller {
   @RequestMapping(method = RequestMethod.GET) 
   public ModelAndView insertPerfinfoGet(HttpServletRequest request,Model model){
     String user=request.getParameter("user");
   }

   @RequestMapping(method = RequestMethod.POST) 
   public ModelAndView insertPerfinfoPOST(@RequestBody Perf perf,Model model) {
     // control not comes here .. when i give post request via REST client
   }

}

仅供参考:      工作

  1.url is : http://server.port/webapp/insertperf?user=java&status=enable
  1.1.for GET method it is working fine as i expected .

Not working :
  2.i have created the Perf POJO in my web layer for query string parameter.
  2.2 passing the parameter via RESTClient with POST method.
  2.3 415 post method not available message

有什么建议吗?提前谢谢。

此致 Vasanth D

2 个答案:

答案 0 :(得分:0)

首先,在您的注释结尾处有一个缺少引号。

另外,尝试从Class定义中删除RequestMapping注释并修改方法的ReqeustMapping注释:

@RequestMapping(method=RequestMethod.GET,value = "/insertperfinfo")

@RequestMapping(method=RequestMethod.POST,value = "/insertperfinfo")

答案 1 :(得分:0)

尝试将POST方法的返回类型更改为Perf。另外,使用@ResponseBody对其进行注释。最后,我认为不需要Model。像这样:

   @RequestMapping(method = RequestMethod.POST) 
   @ResponseBody
   public Perf insertPerfinfoPOST(@RequestBody Perf perf) {
     ...
   }