如果一个接口只接受get请求,那么可以在@RequestMapping的method属性指定get请求
@ResponseBody
@RequestMapping(value = "/springboot",method = RequestMethod.GET)
public Object hi(Model model,String name){
model.addAttribute("name",name);
return myname+"---"+school;
}
springmvc提供了更方便的注解@GetMapping效果同上
@ResponseBody
@GetMapping(value = "/springboot")
public Object hi(Model model,String name){
model.addAttribute("name",name);
return myname+"---"+school;
}
同理 ,Post使用@PostMapping
@ResponseBody
@PostMapping(value = "/springboot")
public Object hi(Model model,String name){
model.addAttribute("name",name);
return myname+"---"+school;
}