接收请求参数:
请求: home/testRequstParam?uid=123&uname=ZhangSan
/** * 接收请求参数 * 路径 home/testRequstParam?uid=123&uname=ZhangSan * @param uid * @param uname * @return */ @RequestMapping("/testRequstParam") public String testRequstParam( @RequestParam("uid") int uid, @RequestParam("uname") String uname){ System.out.println("uid:" + uid + ",uname=" + uname); return "home_index"; }
控制台输出:uid:123,uname=ZhangSan
接收请求参数(可选参数,默认值)
请求: home/testRequstParam2?uid=123
/** * 接收请求参数(可选参数,默认值) * 路径 home/testRequstParam2?uid=123 * @param uid * @param uname * @return */ @RequestMapping("/testRequstParam2") public String testRequstParam2( @RequestParam(value="uid", required=false, defaultValue="0") int uid, @RequestParam(value="uname", required=false) String uname){ System.out.println("uid:" + uid + ",uname=" + uname); return "home_index"; }
控制台输出:uid:123,uname=null