1.使用HttpServletRequest接收
java 代码
/**
* 测试 HttpServletRequest 接收参数
*
* */
@RequestMapping(value = "/test")
@ResponseBody
public String queryAll(HttpServletRequest request) {
System.out.println(request.getParameter("date"));
return request.getParameter("date");
}
jsp 代码
<div>
<form id="mobileCreateOrderListForm" method="post">
<table style="width:100%;">
<tr>
<td>日期:</td>
<td><input name="date" id="date" class="mini-datepicker" ></input></td>
</tr>
</table>
</form>
</div>
2.使用 @RequestParam 接收参数
java 代码
/**
* 测试 @RequestParam 接收参数
*
* */
@RequestMapping(value = "/test")
@ResponseBody
public void queryDicByTypeId(@RequestParam Integer typeId){
System.out.println(typeId);
}
jsp 代码
<div>
<form id="mobileCreateOrderListForm" method="post">
<table style="width:100%;">
<tr>
<td>类型:</td>
<td><input name="typeId" id="typeId" class="mini-textbox" ></input></td>
</tr>
</table>
</form>
</div>
3.使用 @PathVariable 接收参数
Java 代码
/**
* 测试 @RequestParam 接收参数 一个参数
*
* */
@RequestMapping(value = "/testOne/{name}")
@ResponseBody
public void testOne(@PathVariable String name){
System.out.println(name);
}
/**
* 测试 @RequestParam 接收参数 多个参数
*
* */
@RequestMapping(value = "/testMany/name/{name}/sex/{sex}")
@ResponseBody
public void testMany(@PathVariable String name,@PathVariable String sex){
System.out.println(name);
}
3.使用 @RequestBody 接收参数
/**
* 测试 @RequestBody 接收参数 转换成对象
*
* */
@RequestMapping(value = "/test")
@ResponseBody
public void testMany(@RequestBody People people){
System.out.println(people.getName());
System.out.println(people.getSex());
}
jsp代码
<div>
<form id="mobileCreateOrderListForm" method="post">
<table style="width:100%;">
<tr>
<td>姓名:</td>
<td><input name="name" id="name" class="mini-textbox" ></input></td>
<td>性别:</td>
<td><input name="sex" id="sex" class="mini-textbox" ></input></td>
</tr>
</table>
</form>
</div>
本文出自 “7619052” 博客,转载请与作者联系!
原文地址:http://7629052.blog.51cto.com/7619052/1744053