Spring @RequestMapping

 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(..){
05     }
06     @RequestMapping("/edit")
07     public String edit(..){
08     }
09     @RequestMapping("/delete")
10     public String delete(..){
11     }
12 }

2. 结合URL和请求函数

1 @RequestMapping("/user/add")
2 public class UserController {
3     @RequestMapping(methods=RequestMethod.GET)
4     public String form(..){
5     }
6     @RequestMapping(methods=RequestMethod.POST)
7     public String submit(..){
8     }
9 }

3. 函数等级的接口

1 @RequestMapping
2 public class UserController {
3     @RequestMapping("/hello")
4     public String hello(..){
5     }
6     @RequestMapping("/main")
7     public String main(..){
8     }
9 }

4. @RequestMapping 省略

1 @Controller
2 public class UserController {
3     @RequestMapping("/hello")
4     public String hello(..){
5     }
6     @RequestMapping("/main")
7     public String main(..){
8     }
9 }

5. Controller @RequestMapping : 单独接触

1 @RequestMapping("/hello")
2 public class UserController implements Controller{
3     ...
4 }

6. 用函数名称接触

01 @RequestMapping("/user/*")
02 public class UserController {
03     @RequestMapping
04     public String add(..){
05     }
06     @RequestMapping
07     public String edit(..){
08     }
09     @RequestMapping
10     public String delete(..){
11     }
12 }

7. Generic 

01 package com.testone.my;
02  
03 import java.util.List;
04  
05 import org.springframework.web.bind.annotation.RequestMapping;
06  
07 public abstract class GenericController<T,P,S> {
08     S service;
09     @RequestMapping("/add")
10     public void add(T entity){
11     }
12     @RequestMapping("/update")
13     public void update(T entity){
14     }
15     @RequestMapping("/view")
16     public T view(P id){
17         return null;
18     }
19     @RequestMapping("/delete")
20     public void delete(P id){
21     }
22     @RequestMapping("/list")
23     public List<T> list(){
24         return null;
25     }  
26 }
- 个别接触
1 package com.testone.my;
2  
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){
8     }
9 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值