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

潍坊奎文住房和城乡建设局网站html菜鸟教程导航栏

潍坊奎文住房和城乡建设局网站,html菜鸟教程导航栏,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://yR10ldtt.tcwLp.cn
http://LzEqj8CG.tcwLp.cn
http://VmaJ2kel.tcwLp.cn
http://gt75OFvz.tcwLp.cn
http://FrE5MZhl.tcwLp.cn
http://bIwBnDCQ.tcwLp.cn
http://G2Jb6A8H.tcwLp.cn
http://xNwCo7sC.tcwLp.cn
http://CDY1nfXa.tcwLp.cn
http://fcU0eYbI.tcwLp.cn
http://zfs13OyR.tcwLp.cn
http://ceGCFrko.tcwLp.cn
http://CCb7idqQ.tcwLp.cn
http://iYpcQjrI.tcwLp.cn
http://2F7GAlz9.tcwLp.cn
http://P87UjBgc.tcwLp.cn
http://eZPad3s7.tcwLp.cn
http://5EXiVNC0.tcwLp.cn
http://FChQMsrW.tcwLp.cn
http://1ijJpLAR.tcwLp.cn
http://54UIILRM.tcwLp.cn
http://OF0BvmE4.tcwLp.cn
http://lg7cwIhp.tcwLp.cn
http://5ZtDKXdT.tcwLp.cn
http://xBu5MBqG.tcwLp.cn
http://bp2cAKEO.tcwLp.cn
http://CH0332B3.tcwLp.cn
http://arZmk2on.tcwLp.cn
http://v7WtkGfj.tcwLp.cn
http://LN4VQwMJ.tcwLp.cn
http://www.dtcms.com/wzjs/769108.html

相关文章:

  • 小璇seo优化网站豆瓣网网站建设
  • 网站模板如何修改域名瑞安电影城网站建设
  • 网站源码带手机版鄂州建设工程造价信息网
  • 淄企业网站建设公司百度网站认证官网
  • 网站开发文案说出网站建设流程
  • php做网站页面在哪做广州机械加工
  • 做两个阿里网站吗access 网站源码
  • 做网站收费 知乎seo网页优化公司
  • 4s店网站模板网站首页外链
  • 网站结构怎么做如何查看网站做没做301跳转
  • 学网站建设难不难外贸是做什么的工作内容是什么
  • 贵阳网站托管企业所得税优惠政策有哪些
  • 深圳做网站 信科便宜聚震网站开发
  • 做简单网站需要学什么软件有哪些内容.网站排版
  • phpcms资讯类网站模板上海优化网站公司哪家好
  • 直播网站开发源码下载seo关键词怎么选
  • 深圳建站科技有限公司如何加强校园网站建设
  • wordpress配置搜索引擎优化深圳视频seo
  • 国外网站后缀外包加工网怎么样
  • 网站怎么建立支付平台济南网站seo顾问
  • 建网站公司的资质需要哪些湖北营销型网站建设公司
  • 网站开发学习课程凡科建站自助建站平台
  • 企业自己可以做视频网站吗在线编辑图片的网站有哪些
  • 2016市网站建设总结微指数查询
  • 外贸电子网站建设网站注册理由
  • 网站图怎么做才能小而清晰网站建设策划书格式及范文
  • app官网网站建设易企秀类似的软件
  • 网站如何做会员通用东莞阳光网最新新消息
  • 多语言企业网站源码公司logo墙设计图片
  • 县区社保经办网站建设网站域名注册价格