Springboot 实现 Restful 服务,基于 HTTP / JSON 传输
摘要: ysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “怎样的人生才是没有遗憾的人生?我的体会是:(1)拥有健康;(2)创造“难忘时刻”;(3)尽力做好自己,不必改变世界;(4)活在当下。
“怎样的人生才是没有遗憾的人生?我的体会是:(1)拥有健康;(2)创造“难忘时刻”;(3)尽力做好自己,不必改变世界;(4)活在当下。” – 《向死而生》李开复
资源(Resource)资源的表述(Representation)状态转移(State Transfer)统一接口(Uniform Interface)超文本驱动(Hypertext Driven)
面向资源(Resource Oriented)可寻址(Addressability)连通性(Connectedness)无状态(Statelessness)统一接口(Uniform Interface)超文本驱动(Hypertext Driven)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
public class CityRestController {
@Autowired
private CityService cityService;
@RequestMapping (value = "/api/city/{id}" , method = RequestMethod.GET)
public City findOneCity( @PathVariable ( "id" ) Long id) {
return cityService.findCityById(id);
}
@RequestMapping (value = "/api/city" , method = RequestMethod.GET)
public List<City> findAllCity() {
return cityService.findAllCity();
}
@RequestMapping (value = "/api/city" , method = RequestMethod.POST)
public void createCity( @RequestBody City city) {
cityService.saveCity(city);
}
@RequestMapping (value = "/api/city" , method = RequestMethod.PUT)
public void modifyCity( @RequestBody City city) {
cityService.updateCity(city);
}
@RequestMapping (value = "/api/city/{id}" , method = RequestMethod.DELETE)
public void modifyCity( @PathVariable ( "id" ) Long id) {
cityService.deleteCity(id);
}
} |
用云栖社区APP,舒服~
谢谢分享
(来自社区APP)不错,代码很清晰,打算用这个工程做为手机APP的服务