@RequestMapping详解

@RequestMapping详解

简介 @RequestMapping
requestMapping是一个用来处理请求地址映射的的注解,可放在方法或者类上使用,放在方法上表示本类的所有请求都以它为父路径。

requestMapping属性

  1. value:指定请求的地址,支持restful风格
  2. method:指定请求方法的类型,如post,get,delete,put
	@RequestMapping(value="/userAdd.do")
	public String userAdd() {
		System.out.println("this is userAdd");
		return "/success";
	}
	@RequestMapping(value="testPOST.do",method=RequestMethod.POST)
	public String testPost() {
		System.out.println("this is POST");
		return "/success";
	}
  1. consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;
@Controller
@RequestMapping(value = "/addUser.do", consumes="application/json")
public void addUser(Usre user) {    
   
}
  1. produces: 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回
@Controller
@RequestMapping(value = "/userList.do}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public User getUser(int userId) {    
    
    return user;
}

  1. params:指定request中必须包含某些参数值是,才让该方法处理

  2. headers:指定request中必须包含某些指定的header值,才能让该方法处理请求

@RequestMapping(value = "/user", method = RequestMethod.GET, headers="Referer=http://www.baidu.com/")
  public void findUser() {    
  
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值