RequestParam
作用:把请求中指定名称的参数给控制器中的形参赋值
如果前端提交的字段叫username,但是在控制器中处理的参数不叫username,这样参数就对应不上,那么这个注解RequestParam就是其作用。
@Controller
@RequestMapping("/anno")
public class AnnoController {
@RequestMapping("/testRequestParam")
public String testRequestParam(@RequestParam(name = "name") String username){
System.out.println("testRequestParam执行了");
System.out.println(username);
return "success";
}
}
RequestBody
用于获取请求体内容,直接使用得到的是key=value&key=value的结构的数据
get不适用,因为get的方法相当于在url加上附属的提交信息。
而post就是以表单形式存在的
pathvariable注解
用于绑定url中的占位符
@RequestMapping("/testPathVariable/{id}")
public String testPathVariable(@PathVariable(name = "id") String id){
System.out.println("testPathVariable执行了");
System.out.println(id);
return "success";
}
<a href="anno/testPathVariable/10">RequestParam</a>
RequestHeader
获取请求头
CookieValue
用于把指定cookie名称的值传入控制器方法参数
ModelAttribute
可以修饰方法和参数
如果放在方法上,表示会在控制器的方法执行之前,先执行,它可以修饰没有返回值的方法,也可以修饰有具体返回值的方法
放在参数上,获取指定的数据给参数赋值
SessIonAttribute
用于多次执行控制器方法间的参数共享
来源:CSDN
作者:宫城诗
链接:https://blog.csdn.net/qq_36344771/article/details/104063063