Spring(002)-创建rest服务

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;
}

}
 

 

posted @ 2019-11-13 23:09  ibrake  阅读(193)  评论(0编辑  收藏  举报