赞
踩
<fieldset>
<legend>用户注册1</legend>
<form action="/value1" method="post">
用户名:<input type="text" name="username"/><br/>
密 码:<input type="password" name="password"/><br/>
<input type="submit" value="提交"/>
</form>
</fieldset>
@RequestMapping("/value1")
ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception{
String username=request.getParameter("username");
String password=request.getParameter("password");
User u=new User(username, password);
System.out.println(u);
return null;
}
<fieldset>
<legend>用户注册2</legend>
<form action="/value2" method="post">
用户名:<input type="text" name="username"/><br/>
密 码:<input type="password" name="password"/><br/>
<input type="submit" value="提交"/>
</form>
</fieldset>
@RequestMapping("/value2")
ModelAndView value2(String username, String password) throws Exception{
User u=new User(username, password);
System.out.println(u);
return null;
}
如果前台名字和后台形参名字不一致的情况,使用@RequestParam(“前台指定名称”)注解来进行处理:
@RequestMapping("/value3")
ModelAndView value3(@RequestParam("username")String name, String password) throws Exception{
User u=new User(name, password);
System.out.println(u);
return null;
}
<fieldset>
<legend>用户注册4</legend>
<form action="/value4" method="post">
用户名:<input type="text" name="username"/><br/>
密 码:<input type="password" name="password"/><br/>
<input type="submit" value="提交"/>
</form>
</fieldset>
@RequestMapping("/value4")
ModelAndView value4(User u) throws Exception{
System.out.println(u);
return null;
}
http://localhost:8080/temp/6
@RequestMapping("/temp/{abc}")
ModelAndView value5(@PathVariable("abc")String name) throws Exception{
System.out.println(name);
return null;
}
@ResponseBody
@RequestMapping("test")
public void test( @RequestBody List<Integer> list) { //required=false 表示参数非必须
for (Integer integer : list) {
System.out.println(integer);
}
}
[1,2,5]
json方式请转到大标题,json传参(get请求不行)
下面这种请求方式传参同时适用于post请求和get请求
@ResponseBody
@RequestMapping("test")
public void test(@RequestParam(value="list",required = false) List<Integer> list) {
for (Integer integer : list) {
System.out.println(integer);
}
}
@GetMapping("/queryMenuDetailById")
public ResponseEntity<BasiccBfmMenu> queryById(@RequestParam Long id);
http://localhost:8080/queryMenuDetailById
@GetMapping("/queryMenuDetailById")
public ResponseEntity<BasiccBfmMenu> queryById(Long id);
http://localhost:8080/queryMenuDetailById?id=3&ljj=2434
@PostMapping("/editDir")
public ResultVO editDir(@RequestBody DirDto dirDto);
public R<Boolean> delete(@RequestBody String id)
{"id":"1527312204482969600"}
这个时候id的值将会是 {“id”:“1527312204482969600”} 而不是1527312204482969600
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。