通过原生HttpServletRequest获取前端参数
@RequestMapping("/param1")
public String param1(HttpServletRequest request){
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username+" "+password);
return null;
}
前端页面参数和Controller方法参数名一致/不一致的获取方式
一致
@RequestMapping("/param2")
public String param2(String username,String password){
System.out.println(username+" "+password);
return null;
}
不一致:使用@RequestParam
@RequestMapping("/param3")
public String param3(@RequestParam(name = "name") String username,@RequestParam(name = "upwd") String password){
System.out.println(username+" "+password);
return null;
}
使用实体类获取
@RequestMapping("/param4")
public String param4(User user){
System.out.println(user);
return null;
}
地址栏传参(针对RestFul 风格请求路径)
@PathVariable
@RequestMapping("/param6/{username}/{password}")
public String param6(@PathVariable("username") String username,@PathVariable("password") String password){
System.out.println(username+" "+password);
return null;
}
``