标签:
@RequestMapping("testRequestParam") public String filesUpload(@RequestParam String inputStr, HttpServletRequest request) { System.out.println(inputStr); int inputInt = Integer.valueOf(request.getParameter("inputInt")); System.out.println(inputInt); // ......省略 return "index"; }
<form action="/gadget/testRequestParam" method="post"> 参数inputStr:<input type="text" name="inputStr"> 参数intputInt:<input type="text" name="inputInt"> </form>
@RequestParam String inputStr // 下面的对传入参数指定为aa,如果前端不传aa参数名,会报错 @RequestParam(value="aa") String inputStr
// required=false表示不传的话,会给参数赋值为null,required=true就是必须要有 @RequestMapping("testRequestParam") public String filesUpload(@RequestParam(value="aa", required=true) String inputStr, HttpServletRequest request)
@RequestMapping("testRequestParam") public String filesUpload(@RequestParam(value="aa", required=true) String inputStr, @RequestParam(value="inputInt", required=false) int inputInt ,HttpServletRequest request) { // ......省略 return "index"; }
标签:
原文地址:http://www.cnblogs.com/ChrisMurphy/p/4877980.html