@Controller
public class ClinicController{
private final Clinic clinic;
@Autowired
public ClinicController(Clinic clinic){
this.clinic = clinic;
}
@RequestMapping("/")
public void welcomeHandler(){
}
@RequestMapping("/vets")
public ModelMap vetsHandler(){
return new ModelMap(this.clinic.getVets());
}
}
以上代码没有指定请求必须是get方法还是put/post或其他方法,@RequestMapping注解默认会映射所有的HTTP请求方法,如果仅想接受某种请求方法,请在注解中指定@RequestMapping(method = GET)以缩小范围
The above example does not specify GET vs PUT,POST and so forth,because @RequestMapping maps all HTTP methods by default.