1.
@Controller
@RequestMapping(path = "/user")//一级目录
public class FormSubmit {
@RequestMapping(path = "/save")//二级目录 /user/save
public String typeCase(@RequestParam(name = "name") String username, User user, HttpServletRequest request//获得原生的Servlet API) {
return "success";
}
}
注解 | 解释 |
@RequestMapping |
RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。 属性: value: 指定请求的实际地址,指定的地址可以是URI Template 模式,@RequestMapping 中还支持通配符“* ” method: 指定请求的method类型, GET、POST、PUT、DELETE等 consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html; params: 指定request中必须包含某些参数值是,才让该方法处理。 |
@PathVariable | 拿到@RequestMapping(path="/pathVariable/{id}")中{}中携带的参数 (@PathVariable(name="id") String id) |
@RequestHeader | 获得指定的请求头(@RequestHeader(value="Accept") String header) |
@RequestBody | 获得所有请求体(@RequestBody String body) |
@RequestParam | 当请求中的参数名与映射的接受的参数名不同时,用与接受不同名的参数@RequestParam(name = "name") String username, |
@CookieValue( | 获得指定的CookieValue @CookieValue(value="JSESSIONID") String cookie |