Spring 常用注解

1.常用注解
@RequestMapping(value=“p”) 用于映射路径
@RequestParam(“name”) String userName 用户获取@RequestParam指定名称的参数 赋值给装饰的变量 /p?name=aaa
@PathVariable
rest风格是一种设计风格
将互谅网上所有的东西看做是一个资源,使用URI(统一资源标示符)互联网协议号://授权(用户名@主机名:端口)/PATH
GET 对资源的读取 (查询)
POST 新增资源
PUT 修改资源
DELETE 删除资源
rest风格要求将动作体现在请求method中 uri指向一个资源(只能是名词)要求你返回数据类型 json 不能使jsp html

http协议乱 uri
GET http://localhost:8080/sp/user/1
1.多条件搜索
http://localhost:8080/sp/user
请求体 返回多个对象

    2.主键搜索
         http://localhost:8080/sp/user/1  返回一个对象

 POST
    http://localhost:8080/sp/user
     请求体
 PUT
   http://localhost:8080/sp/user/1
     请求体

 DELETE  
   http://localhost:8080/sp/user/1

请求头相关注解
@RequestHeader(“User-Agent”) String userAgent 获取User-Agent请求头到userAgent变量
@CookieValue(“JSESSIONID”) String JSESSIONID 获取JSESSIONID cookie值到 变量JSESSIONID

2.rest风格实现

rest风格 默认html不支持 需要添加springmvc的过滤器
web.xml

httpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter


httpMethodFilter
/*

put和delete请求表单添加(注意表单必须是post请求)

路径映射
@RequestMapping(value="/user/{userId}",method = RequestMethod.GET)
@RequestMapping(value="/user/{userId}",method = RequestMethod.POST)
@RequestMapping(value="/user/{userId}",method = RequestMethod.PUT)
@RequestMapping(value="/user/{userId}",method = RequestMethod.DELETE)
获取路径参数
@RequestMapping(value="/user/{userId}",method = RequestMethod.GET)
public String query(@PathVariable String userId){
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值