spring boot post modelandview错误

时间:2014-11-14 13:41:55

标签: java spring spring-mvc http-post spring-boot

我正在做角度和弹簧靴的工作。

我的工作请求适用于HTTP GET s, 但我遇到POST请求控制器返回null

的问题

这是有效的:

@RequestMapping(value="/foo.do", method=RequestMethod.GET)
@ResponseBody
public ModelAndView indexStringGet(Model model, @RequestParam(id) String orderId,
        HttpServletRequest request){
    System.out.println("=== get Index");//
    System.out.println("=== orderId" + orderId);

     String path = request.getContextPath();        
     System.out.println("== path" + path);
    ModelAndView mv = new ModelAndView();
    mv.setViewName("test1");
    return mv;
}   

但不支持此Request方法'POST'

@RequestMapping(value="/foo.do", method=RequestMethod.POST)
@ResponseBody
public ModelAndView indexStringPost(Model model, @RequestParam(id) String orderId,
HttpServletRequest request){
System.out.println("=== get Index");//
System.out.println("=== orderId" + orderId);

 String path = request.getContextPath();        
 System.out.println("== path" + path);
ModelAndView mv = new ModelAndView();
mv.setViewName("test1");
return mv;
}   

这是结果:

"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/SpringBoot/test1"

由于

0 个答案:

没有答案