对Spring MVC常用注解的理解

因为工作中经常用到的注解,特此写个博客,记录一下,方便自己和他人解决问题

  • NO.1 @requestMapping
@requestMapping(path/value = {"/vip/list","/svip/list"}, method = {requestMethod.GET,reqeustMethod.POST})
public String method_1(HttpServletRequest request, HttpServletResponse response) {
 return "index";   
}

key:name/value/(不写)都是可以的,作用是一样的

value:可以是一个数组,也可以是一个字符串,如果是字符串的话,只能访问这个请求,如果是数组的话,访问某个数组中的一个就可以

method表示访问该方法必须是什么类型,这里表示的是仅支持get和post请求,如果不写method属性的话,默认是8个请求类型都支持

  • NO.2 @requestParam
@requestMapping(name/value = {"/vip/list","/svip/list"}, method = {requestMethod.GET,reqeustMethod.POST})
public String method_2(@requestParam(name/value = "id",defaultValue = "1",required = true/false) Integer id,HttpServletRequest request, HttpServletResponse response) {
 return "index";   
}

key:defaultValue表示id没有的话,默认是对应的value中的值1

下班在更吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值