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

手机看黄山网站大淘客做自己网站

手机看黄山网站,大淘客做自己网站,c 做的网站怎么上传,中国风 wordpress主题REST简介 REST(Representational State Transfer)即表现层状态转移,是一种基于HTTP协议的网络应用程序的架构风格。它强调客户端和服务器之间的交互操作,通过对资源的表现形式进行操作来实现对资源的管理。REST风格的API设计具有简…

REST简介

    REST(Representational State Transfer)即表现层状态转移,是一种基于HTTP协议的网络应用程序的架构风格。它强调客户端和服务器之间的交互操作,通过对资源的表现形式进行操作来实现对资源的管理。REST风格的API设计具有简单、灵活、可扩展等特点,因此在Web开发中得到了广泛应用。

优点

  • 隐藏资源的访问路径,无法通过地址资源得知对资源是何种操作
  • 书写简化

REST风格

按照REST风格访问资源时使用了行为动作区分对资源进行了何种操作

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

 注: 上述行为是约定方式,并不是规范,描述模块的名称通常是复数。

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

RESTful入门案例

    截止目前的学习,当前写法为:

@Controller
public class UserController {@RequestMapping("/save")@ResponseBodypublic String save(@RequestBody User user) {System.out.println("user save..." + user);return "{'module':'user save'}";}@RequestMapping("/delete")@ResponseBodypublic String delete(Integer id) {System.out.println("user delete..." + id);return "{'module':'user delete'}";}@RequestMapping("/update")@ResponseBodypublic String update(@RequestBody User user) {System.out.println("user update..." + user);return "{'module':'user update'}";}@RequestMapping("/getById")@ResponseBodypublic String getById(Integer id) {System.out.println("user getById..." + id);return "{'module':'user getById'}";}@RequestMapping("/getAll")@ResponseBodypublic String getAll() {System.out.println("user getAll" );return "{'module':'user getAll'}";}
}

REST写法为:

@Controller
public class UserController {@RequestMapping(value = "/users",method = RequestMethod.POST)@ResponseBodypublic String save(@RequestBody User user) {System.out.println("user save..." + user);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'}";}
}

其中:@PathVariable表示路径变量作用是绑定路径参数与处理器方法形参间的关系(路径参数名要与形参名一致),传入参数时无需向之前?key=value那样,@RequestMapping中value的值也要接上{参数名}用于传递参数

简化开发

    在上面的案例中,有许多重复使用的注解

  •     @RequestMapping将重复的路径提取到类上面,同样@ResponseBody同理。
  •     @ResponseBody可以和@Controller合并成@RestController。
  •     @RequestMapping(method = RequestMethod.POST)可以简化成@PostMapping
  •     @RequestMapping内还有value时也可以进行简化@DeleteMapping("/{id}")

最终的写法如下:

@RestController
@RequestMapping("/users")
public class UserController {@PostMappingpublic String save(@RequestBody User user) {System.out.println("user save..." + user);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.dtcms.com/wzjs/563338.html

相关文章:

  • 海南爱心扶贫网站是哪个公司做的文创产品设计理念
  • 茌平微网站建设离我最近的广告公司在哪里
  • 网站建设编辑器凡客软件
  • 网站备案周期做app还是做网站
  • 移动端h5网站开发服务做淘客网站 知乎
  • 怎么找上海网站建设模板建站价格
  • 石家庄制作公司网站天长网站设计
  • angularjs开发网站模板做淘宝链接的网站
  • 小说网站建设需要什么一个网站通常包含多个网页
  • 北京三原色ps网站惠城营销网站制作
  • 在什么网站下载wordpress大型平台网站开发
  • 什么是网站评价建设网站多长时间
  • 免费下ppt课件的网站有没有免费的网站
  • 做超市促销海报哪个网站好金湖县住房和城乡建设局网站
  • 网站建设报价购物品牌建设 宣传
  • 网站建设來超速云建站网站开发后端 书
  • 海外网站cdn加速下载咸阳市城乡建设规划局网站
  • 网站建设跳转页面怎么弄wordpress如何修改首页
  • 网站建设评价量规自己如何做购物网站
  • 南京 网站建设wordpress文章百度主动推送
  • 西部数码网站管理助手v3.0如何使用网站营销
  • sap软件网站优化设计公司
  • win10使用dw做网站牡丹江做网站的公司
  • php教育视频网站开发如何网络推广推广
  • 企业手机网站开发上传到网站空间
  • 没有网站可以做百度快照怎么做高端网站设计有哪些
  • jsp购物网站开发 论文wordpress 128m内存
  • 成都市建设领域信用系统网站创做网站
  • 从化企业网站建设wordpress企业商城模板
  • 个人网站注册平台要多少钱互联网公司排名2019