1. 程式人生 > >Spring boot請求引數

Spring boot請求引數

GET請求:

1.restful風格:

@GetMapping("/order/detail")
public BaseOutput omsQueryDetail(@RequestParam("orderId") String id) {
}

2.resultful風格:

@GetMapping("/order/detail/{orderId}")
public BaseOutput omsQueryDetail(@PathVariable String orderId) {
}

POST請求:

@PostMapping("/order/detail")
public BaseOutput orderDetail(@RequestBody OrderDetailReq req) {
}

 

一些情況:

1.使用@RequestParam,引數不一定存在時

@RequestParam(name="id",required=false)
@RequestParam(name="id",required=false,defaultValue="0")