RESTful最佳实践之基于 jersey 的增删改查

RESTful最佳实践之基于 jersey 的增删改查

jersey-rest-demo 增删改查

项目地址:https://github.com/CoderDream/jersey-rest-demo

源代码:http://download.youkuaiyun.com/detail/xuxiheng/8227849


查找
  1. 直接访问 地址:http://localhost:8080/jersey-rest-demo/rest/contacts/ Image
  2. PostMan访问 地址:http://localhost:8080/jersey-rest-demo/rest/contacts/

    查找所有的记录:

    方法 GET

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts

    Header参数 Accept : application/json

    返回的json {     "contact": [         {             "address": [                 {                     "city": "Shanghai",                     "street": "Long Hua Street"                 },                 {                     "city": "Shanghai",                     "street": "Dong Quan Street"                 }             ],             "id": "huangyim",             "name": "Huang Yi Ming"         },         {             "id": "a1",             "name": "a1"         }     ] }

    Image(9)

    查找指定ID的记录:

    方法 PUT

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数 Content-Type : application/json

    返回的json

    {     "id": "a1",     "name": "a1" }

    Image(10)


新增
  1. 通过页面添加: 新增:http://localhost:8080/jersey-rest-demo/pages/new_contact.jsp Image(2) 查询:http://localhost:8080/jersey-rest-demo/rest/contacts Image(3)
  2. 通过Chrome的插件PostMan 实例1(只包含id和name):

    方法 PUT

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数 Content-Type : application/json

    请求的json

    {     "id": "abc",     "name": "123" }

    Image(4)

    实例2(包含id、name和address列表):

    方法 PUT

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts/a123

    Header参数 Content-Type : application/json

    请求的json {   "address": [     {       "city": "Shanghai",       "street": "Long Hua Street"     },     {       "city": "Shanghai",       "street": "Dong Quan Street"     }   ],   "id": "a123",   "name": "Huang Yi Ming"   }

    Image(11)


修改
  1. 修改记录

    方法 PUT

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数 Content-Type : application/json

    请求的json {     "id": "abc",     "name": "12345" }

    Image(5)

  2. 查看更新后的结果

    方法

    GET

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接

    http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数

    Accept : application/json

    返回的json

    {     "id": "abc",     "name": "12345" }

    Image(6)


删除
  1. 删除记录

    方法 DELETE

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接 http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数 Content-Type : application/json

    Image(7)

  2. 删除后查看结果  

    方法

    GET

    语法

    http://localhost:8080/jersey-rest-demo/rest/contacts/{contactId}

    链接

    http://localhost:8080/jersey-rest-demo/rest/contacts/abc

    Header参数

    Accept : application/json

    Image(8)


参考文档
  1. 在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值