作者:gqk
通过@RequestParam对简单类型的参数进行绑定。
@RequestMapping("/test1") public String test1(@RequestParam("name")String name, @RequestParam("pwd")String pwd, @RequestParam(defaultValue="110")int age){ System.out.print("name===="+name); System.out.print("pwd===="+pwd); System.out.print("age===="+age); return "hello"; }
<!-- 解决post传入中文乱码问题 -->获取参数如果乱码可以在web.xml中配置过滤器
<filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping>
页面中input的name和controller的pojo形参中的属性名称一致,将页面中数据绑定到pojo对应的属性。
@RequestMapping("/test2") public String test2(User user){ System.out.print(user); return "hello"; }
1 @RequestMapping("/test3") 2 public String test3(Integer[]ids ){ 3 System.out.print(ids); 4 return "hello"; 5 }
原文:https://www.cnblogs.com/520gqk/p/12168753.html