1:@RequestParam(value="id",defaultValue="0") String id
id:get set
UI:?id=***
可以用Map<String, Object>,其键值可以在页面上用EL表达式${键值名}得到,
3)也可以用Model类对象来传递,有addAttribute(key, value)方法,其键值可以在页面上用EL表达式${键值名}得到,
即有一个User类,如下
package model;
public class User {
private String name ;
private String hobby ;
public User(){
}
public User(String name, String hobby) {
this.name = name;
this.hobby = hobby;
}
//...get/set方法略
则页面上可以用
<form name="form1" action="hello4" method="post">
<input type="text" name="name"/>
<input type="text" name="hobby"/>
2 consumes、produces 示例
cousumes的样例:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller
@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")
public void addPet(@RequestBody Pet pet, Model model) {
// implementation omitted
}
方法仅处理request Content-Type为“application/json”类型的请求。
produces的样例:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
}
方法仅处理request请求中Accept头中包含了"application/json"的请求,同时暗示了返回的内容类型为application/json;
如果请求中有多个同名的应该如何接收呢?如给用户授权时,可能授予多个权限,首先看下如下代码:
public String requestparam7(@RequestParam(value="role") String roleList)
如果请求参数类似于url?role=admin&rule=user,则实际roleList参数入参的数据为“admin,user”,即多个数据之间使用“,”分割;我们应该使用如下方式来接收多个请求参数:
var arr = new Array();
arr.push()
public String requestparam7(@RequestParam(value="role") String..args)
或
public String requestparam8(@RequestParam(value="list") List<String> list)
到此@RequestParam我们就介绍完了,以上测试代码在cn.javass.chapter6.web.controller. paramtype.RequestParamTypeController中。
id:get set
UI:?id=***
可以用Map<String, Object>,其键值可以在页面上用EL表达式${键值名}得到,
3)也可以用Model类对象来传递,有addAttribute(key, value)方法,其键值可以在页面上用EL表达式${键值名}得到,
即有一个User类,如下
package model;
public class User {
private String name ;
private String hobby ;
public User(){
}
public User(String name, String hobby) {
this.name = name;
this.hobby = hobby;
}
//...get/set方法略
则页面上可以用
<form name="form1" action="hello4" method="post">
<input type="text" name="name"/>
<input type="text" name="hobby"/>
2 consumes、produces 示例
cousumes的样例:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller
@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")
public void addPet(@RequestBody Pet pet, Model model) {
// implementation omitted
}
方法仅处理request Content-Type为“application/json”类型的请求。
produces的样例:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
}
方法仅处理request请求中Accept头中包含了"application/json"的请求,同时暗示了返回的内容类型为application/json;
如果请求中有多个同名的应该如何接收呢?如给用户授权时,可能授予多个权限,首先看下如下代码:
public String requestparam7(@RequestParam(value="role") String roleList)
如果请求参数类似于url?role=admin&rule=user,则实际roleList参数入参的数据为“admin,user”,即多个数据之间使用“,”分割;我们应该使用如下方式来接收多个请求参数:
var arr = new Array();
arr.push()
public String requestparam7(@RequestParam(value="role") String..args)
或
public String requestparam8(@RequestParam(value="list") List<String> list)
到此@RequestParam我们就介绍完了,以上测试代码在cn.javass.chapter6.web.controller. paramtype.RequestParamTypeController中。