当前位置: 首页 > news >正文

死链接对网站的影响sem是什么

死链接对网站的影响,sem是什么,沈阳哪有做网站的,wordpress注册邮箱发送REST(Representational State Transfer,表现形式状态转换)是一种访问网络资源的格式。传统的资源描述方式通常如下: http://localhost/user/getById?id1http://localhost/user/saveUser 而 REST 风格的描述则更简洁&#xff1a…

REST(Representational State Transfer,表现形式状态转换)是一种访问网络资源的格式。传统的资源描述方式通常如下:

  • http://localhost/user/getById?id=1
  • http://localhost/user/saveUser

而 REST 风格的描述则更简洁:

  • http://localhost/user/1
  • http://localhost/user

采用 REST 风格的优势包括:

  • 隐藏资源访问的具体行为,使得从 URL 无法判断对资源的操作类型
  • 简化书写,提高可读性

在 REST 风格中,通过行为动作来区分对资源的操作类型:

url含义动作
http://localhost/users查询全部用户信息GET(查询)
http://localhost/users/1查询指定用户信息GET(查询)
http://localhost/users添加用户信息POST(新增/保存)
http://localhost/users修改用户信息PUT(修改/更新)
http://localhost/users/1删除用户信息DELETE(删除)

上述行为是一种约定,而非严格的规范,因此称为 REST 风格,而不是 REST 规范。在描述模块名称时,通常使用复数形式(即加 “s”),以表示这一类资源,而非单个资源,例如:users、books、accounts 等。

根据 REST 风格对资源进行访问的方式称为 RESTful

快速入门

REST 风格通常包含两个步骤:

  1. 设定 HTTP 请求动作(动词):通过 @RequestMapping 注解的 method 参数来指定。
  2. 设定请求参数(路径变量):通过 @PathVariable 注解来定义路径变量。

以下是使用 REST 风格的代码示例:

@Controller
public class UserController {@RequestMapping(value = "/users", method = RequestMethod.POST)@ResponseBodypublic String save() {System.out.println("user save ...");return "{'module': 'user save'}";}@RequestMapping(value = "/users/{id}", method = RequestMethod.DELETE)@ResponseBodypublic String delete(@PathVariable Integer id) {System.out.println("user delete ..." + id);return "{'module': 'user delete'}";}@RequestMapping(value = "/users", method = RequestMethod.PUT)@ResponseBodypublic String update(@RequestBody User user) {System.out.println("user update ..." + user);return "{'module': 'user update'}";}@RequestMapping(value = "/users/{id}", method = RequestMethod.GET)@ResponseBodypublic String getById(@PathVariable Integer id) {System.out.println("user getById ..." + id);return "{'module': 'user getById'}";}@RequestMapping(value = "/users", method = RequestMethod.GET)@ResponseBodypublic String getAll() {System.out.println("user getAll ...");return "{'module': 'user getAll'}";}
}

@RequestBody vs @RequestParam vs @PathVariable

  • 区别

    • @RequestParam:用于接收 url 地址传参或表单传参
    • @RequestBody:用于接收 JSON 数据
    • @PathVariable:用于接收路径参数,使用 {参数名称} 描述路径参数
  • 应用

    • 后期开发中,发送请求参数超过 1 个时,以 JSON 格式为主,@RequestBody 应用较广
    • 若发送非 JSON 格式数据,选用 @RequestParam 接收请求参数
    • 采用 RESTful 开发,当参数数量较少,例如1个,可采用 @PathVariable 接收请求路径变量,通常用于传递 id 值

代码优化

从上面的 RESTful 风格代码中,可以看到一些冗余之处,例如每个方法都使用了 @ResponseBody 注解,并且每个方法的 @RequestMapping 都以 /users 为前缀。为了减少代码的重复性,可以将 @ResponseBody@RequestMapping("/users") 注解统一放置在类定义上,并利用特定的动作注解替代方法中的 @RequestMapping

另外,使用 @RestController 注解可以将当前控制器类设置为 RESTful 风格,这个注解等同于 @Controller@ResponseBody 的组合。因此,可以用 @RestController 来代替这两个注解,从而简化代码。

//@Controller
//@ResponseBody
@RestController
@RequestMapping("/users")
public class UserController {@PostMappingpublic String save() {System.out.println("user save ...");return "{'module': 'user save'}";}@DeleteMapping("/{id}")public String delete(@PathVariable Integer id) {System.out.println("user delete ..." + id);return "{'module': 'user delete'}";}@PutMappingpublic String update(@RequestBody User user) {System.out.println("user update ..." + user);return "{'module': 'user update'}";}@GetMapping("/{id}")public String getById(@PathVariable Integer id) {System.out.println("user getById ..." + id);return "{'module': 'user getById'}";}@GetMappingpublic String getAll() {System.out.println("user getAll ...");return "{'module': 'user getAll'}";}
}
http://www.yidumall.com/news/16092.html

相关文章:

  • 网页设计旅游网站前言数字营销工具
  • 入侵织梦网站后台免费发广告帖子的网站
  • 商城网站做推广方案沈阳线上教学
  • 西安市城乡房地产建设管理局网站一级消防工程师考试
  • 百度推广送的公司网站有什么用seo网站自动推广
  • 一家专门做男人的网站seo百度关键词优化软件
  • 企业网站开发项目策划书基本框架新手做seo怎么做
  • 做舞台灯光的在哪些网站接订单呢网站运营包括哪些内容
  • 微信公众号网站怎么做广告设计与制作需要学什么
  • vs做网站怎么上设计素材网站
  • 网站改版提示无需改版企业网站的优化建议
  • 学网站设计和平面设计北京网站seo优化推广
  • 招聘网站开发的公司广州seo工程师
  • 做公司网站找谁专业黑帽seo推广
  • wordpress站点app开发百度图片识别在线识图
  • 支付网站建设百度推广网站一年多少钱
  • 南充能够建设网站的公司有百度新闻首页头条
  • 贵州新冠疫情最新消息seo优化网站快速排名
  • 大连百姓网免费发布信息网站企业员工培训课程内容
  • asp.net实用网站开发doc怎么引流怎么推广自己的产品
  • 网站是不是网页销售
  • php用户管理系统东莞seo排名收费
  • 做传销网站违法的吗app开发
  • 广州网站建设懂你所需神马快速排名优化工具
  • 做外汇模拟的网站优化关键词首页排行榜
  • wordpress http2十堰seo优化方法
  • 企业网站的特点是什么文库百度登录入口
  • wordpress的主题是什么凯里seo排名优化
  • 南昌个人做网站太原网站建设开发
  • 网站建设毕业设计总体规划郑州今天刚刚发生的新闻