一般会报如下错:
-
Request Method:POST
-
Status Code:415 Unsupported Media Type
加上去就可以,程序写起来就爽很多了,简单例子如下:
还有在Controller类上面不要加上produce="text/plan;charset=utf-8",不然也会出现406,因为返回的是json
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping("/index")
public @ResponseBody Student index(){
Student student=new Student();
student.setAge(1);
student.setName("中国人");
return student;
}
@RequestMapping(value="/add",method=RequestMethod.POST)
public @ResponseBody String add(Student student){
return student.getName();
}
@RequestMapping("/addUI")
public String addUI(){
return "index";
}
}