# rest-api-web **Repository Path**: mirrors/rest-api-web ## Basic Information - **Project Name**: rest-api-web - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: https://www.oschina.net/p/rest-api-web - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2017-06-25 - **Last Updated**: 2025-10-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## RESTful API by Jersey2 + Spring4 + MyBatis3 + Jetty9 高效的RESTful API服务实现,基于Jersey2和嵌入式的轻量级的servlet容器Jetty9, 这个是war包形式部署到jetty中运行,实现对用户的增、删、改、查操作,并且严格按照RESTful风格设计接口。 ## SQL user table ``` sql -- 用户表 DROP TABLE IF EXISTS t_user; CREATE TABLE t_user ( id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID', name VARCHAR(32) NOT NULL COMMENT '用户名', age int(11) COMMENT '年龄', password VARCHAR(64) COMMENT '密码', created_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT '用户表'; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO t_user(id, name, age, password) VALUES (1, '张飞', 20, 'zhangfei'); INSERT INTO t_user(id, name, age, password) VALUES (2, '赵云', 50, 'zhaoyun'); ``` ## 列出所有用户列表 ``` http://localhost/api/v1/users ``` 结果: ``` [ { "id" : 1, "name" : "张飞", "age" : 20, "password" : "zhangfei", "createdTime" : "2017-06-15 20:38:09", "updatedTime" : "2017-06-15 20:38:09" }, { "id" : 2, "name" : "赵云", "age" : 50, "password" : "zhaoyun", "createdTime" : "2017-06-15 20:38:09", "updatedTime" : "2017-06-15 20:38:09" } ] ``` ## 根据id获取用户信息 ``` http://localhost/api/v1/users/1 ``` 结果: ``` { "id" : 1, "name" : "张飞", "age" : 20, "password" : "zhangfei", "createdTime" : "2017-06-15 20:38:09", "updatedTime" : "2017-06-15 20:38:09" } ``` ------------

***注:下面几种使用chrome的Postman测试*** ## 创建新用户 ```http://localhost/api/v1/users POST``` body参数: ``` { "id" : 3, "name" : "孙权", "age" : 24, "password" : "sunquan" } ``` 返回结果: ``` HTTP code:201 User was successfully created ``` ## 更新用户 ```http://localhost/api/v1/users PUT``` body参数: ``` { "id" : 3, "name" : "孙权", "age" : 25, "password" : "sunquan" } ``` 返回结果: ``` HTTP code:200 User was successfully updated ``` ## 删除用户 ```http://localhost/api/v1/users/3 DELTE``` 返回结果: ``` HTTP code:200 User was successfully deleted ``` ## License (The Apache License) Copyright (c) 2017 [Xiong Neng](https://www.xncoding.com/) and other contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.