1、获取超链接的参数和值
<a href="vote/vote01?name=love">获取超链接的参数</a>
//获取超链接的参数@RequestMapping(value = "/vote01")public String vote01(@RequestParam(value = "name", required=false) String name){System.out.println("得到的userName"+name);return "voteOK";}
2、//获取请求头的参数
<hr><a href="vote/vote02">获取请求头参数</a>
//获取请求头的参数@RequestMapping(value = "/vote02")public String vote02(@RequestHeader("Accept-encoding") String ae){System.out.println("得到的http参数 = "+ae);return "voteOK";}
3、获取javaBean的数据 and 获取原生servlet api
<%--确保这里的name与bean的属性名一致,否则拿不到值--%>
<a>添加主人信息</a>
<form action="vote/vote04" method="post" >主人id:<input type="text" name="id"><br>主人名:<input type="text" name="monsterName"><br>宠物名:<input type="text" name="pet.petName"><br><input type="submit" value="提交" ><br>
</form>
//获取javaBean的数据 and 获取原生servlet api@RequestMapping(value = "/vote03")public String vote03(Monster monster, HttpServletRequest request,HttpServletResponse response){System.out.println("得到的monster = "+monster);System.out.println("masterName = "+ request.getParameter("monsterName"));return "voteOK";}