@RequestParam
用于获取Http请求中的参数,来自于Query String.即SevletRequest#getParameter
@PathVariable
用于获取URI占位符传入的值,一般用在RESTful接口上
@RequestBody
将请求消息体绑定到一个对象上
@ModelAttribute
此注解可以放置于参数上,也可以放置于方法上;
// Add one attribute
// The return value of the method is added to the model under the name "account"
// You can customize the name via @ModelAttribute("myAccount")
@ModelAttribute
public Account addAccount(@RequestParam String number) {
return accountManager.findAccount(number);
}
// Add multiple attributes
@ModelAttribute
public void populateModel(@RequestParam String number, Model model) {
model.addAttribute(accountManager.findAccount(number));
// add more ...
}
往Model中添加属性值,cotroller中每个方法执行之前都会执行这个方法(含有@ModelAttribute注解的方法)
而将ModelAttribute放置于参数上时,表示从Model中获取指定名称的参数;
@SessionAttribute 从spring4.3.x开始有
表示从global session中获取指定名称的参数,并绑定;
@RequestAttribute
表示从Request请求返回内获取指定名称的参数,并绑定
@CookieValue
表示从Http请求 cookie中获取指定名称的参数,并绑定;
其他RESTful相关注解
@Controller
@RestController
@RequestMapping
@ResponseBody
@ExceptionHandler
@ControllerAdvice
@RestControllerAdvice