http://pirrip.tistory.com/70
1. String[] value() : URL patten
@RequestMapping("/hello")
@RequestMapping({"/hello", "/hello/", "/hello.*"})
@RequestMapping("/main*")
@RequestMapping("/view.*")
@RequestMapping("/admin/**/user")
@RequestMapping("/user/{userid}")
2. RequestMethod[] method() : HTTP 请求函数
- RequestMethod : GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE 含有7个常数的 enum
@RequestMapping(value="/user/add", method=RequestMethod.GET)
@RequestMapping(value="/user/add", method=RequestMethod.POST)
3. String[] params() : 请求变数
@RequestMapping(value="/user/edit", params="type=admin")
@RequestMapping(value="/user/edit", params="type=member")
@RequestMapping(value="/user/edit", params="!type")
4. String[] headers() : HTTP header
@RequestMapping(value="/view", headers="content-type=text/*")
1. 结合URL
01 | @RequestMapping ( "/user" ) |
02 | public class UserController { |
03 | @RequestMapping ( "/add" ) |
04 | public String add(..){ |
06 | @RequestMapping ( "/edit" ) |
07 | public String edit(..){ |
09 | @RequestMapping ( "/delete" ) |
10 | public String delete(..){ |
2. 结合URL和请求函数
1 | @RequestMapping ( "/user/add" ) |
2 | public class UserController { |
3 | @RequestMapping (methods=RequestMethod.GET) |
4 | public String form(..){ |
6 | @RequestMapping (methods=RequestMethod.POST) |
7 | public String submit(..){ |
3. 函数等级的接口
2 | public class UserController { |
3 | @RequestMapping ( "/hello" ) |
4 | public String hello(..){ |
6 | @RequestMapping ( "/main" ) |
7 | public String main(..){ |
4. @RequestMapping 省略
2 | public class UserController { |
3 | @RequestMapping ( "/hello" ) |
4 | public String hello(..){ |
6 | @RequestMapping ( "/main" ) |
7 | public String main(..){ |
5. Controller @RequestMapping : 单独接触
1 | @RequestMapping ( "/hello" ) |
2 | public class UserController implements Controller{ |
6. 用函数名称接触
01 | @RequestMapping ( "/user/*" ) |
02 | public class UserController { |
04 | public String add(..){ |
07 | public String edit(..){ |
10 | public String delete(..){ |
7. Generic
01 | package com.testone.my; |
03 | import java.util.List; |
05 | import org.springframework.web.bind.annotation.RequestMapping; |
07 | public abstract class GenericController<T,P,S> { |
09 | @RequestMapping ( "/add" ) |
10 | public void add(T entity){ |
12 | @RequestMapping ( "/update" ) |
13 | public void update(T entity){ |
15 | @RequestMapping ( "/view" ) |
19 | @RequestMapping ( "/delete" ) |
20 | public void delete(P id){ |
22 | @RequestMapping ( "/list" ) |
23 | public List<T> list(){ |
- 个别接触
1 | package com.testone.my; |
3 | import org.springframework.web.bind.annotation.RequestMapping; |
4 | @RequestMapping ( "/user" ) |
5 | public class UserController extends GenericController<User, Integer, UserService>{ |
6 | @RequestMapping ( "/login" ) |
7 | public String login(String userId, String password){ |