-
Notifications
You must be signed in to change notification settings - Fork 70
Spring MVC
luoml edited this page Jul 16, 2017
·
6 revisions
-
value处理方法的请求URL -
method处理方法的Http Method类型,如:RequestMethod.GET -
params请求URL中必须包含(或不包含)的某些参数-
params="var"请求URL中必须包含var参数,如:/find?var=test -
params="!var"请求URL中不能包含var参数 -
params="var=test"请求URL中必须包含var=test,如:/find?var=test -
params="var!=test"请求URL中不能包含var=test
-
-
@RequestMapping支持Ant风格的通配符
-
?匹配任意一个字符 -
*匹配任意多个字符 -
**匹配多层路径
-
@RequestMapping("/user/{id}", method = RequestMethod.GET)
public User get(@PathVariable("id") Integer id) { ... }
// 可以通过 required 设置参数是否必填
@RequestMapping("/user", method = RequestMethod.GET)
public User get(@RequestParam("id") Integer id) { ... }
// jsp
<form method="post" action="*.do">
UserName: <input id="username" type="text" name="username"/>
Password: <input id="password" type="password" name="password"/>
<input type="submit" value="Submit" />
</form>
// po
public class User {
private String username;
private String password;
......
}
// Controller
@RequestMapping(method = RequestMethod.POST)
public void login(@ModelAttribute("user") User user) { ... }
@RequestMapping("/user", method = RequestMethod.GET)
public User get(HttpServletRequest request) { ... }