1. 创建基于 get 参数的 REST 服务
- @RestController
- @RequestMapping("/action")
- public class GetController {
- @GetMapping(value = "/get/{id}",produces = "application/json")
- public Order getAllOrdersByGet(@PathVariable int id) {
- Order order = new Order();
- order.setOrderId(id);
- order.setOrderName(String.format("order:%d", id));
- return order;
- }
- }
2. 创建向服务器 post 数据的 REST 服务
- @RestController
- @RequestMapping("/action")
- public class PostController {
- @PostMapping(value = "/save", consumes = "application/json",produces = "application/json")
- public Order getAllOrdersByPost(@RequestBody Order order) {
- order.setOrderName("orderFromServer");
- return order;
- }
- }
来源: http://www.bubuko.com/infodetail-3286773.html