Spring Boot HTTP接口GET请求

普通传参

1
2
3
4
5
@RequestMapping(path = "/{province_id}/{city_id}", method = RequestMethod.GET)
public Object findUser(@PathVariable("province_id") String provinceId,
@PathVariable("city_id") String cityId) {

}

GetMapping注解

1
2
3
4
@GetMapping(value = "/order/list")
public Object orderList(int from, int size) {

}

默认值、参数名、是否必须

1
2
3
4
@GetMapping(value = "/order/list")
public Object orderList(@RequestParam(defaultValue = "0", name = "page", required = true) int from, int size) {

}

Bean对象传参

1
2
3
4
@GetMapping("/user/add")
public Object saveUser(User user) {

}

获取http头信息

1
2
3
4
@GetMapping("/common/get_header")
public Object getHeader(@RequestHeader("access_token") String accessToken, String id) {

}

HttpServletRequest

1
2
3
4
@GetMapping("/common/servlet_request")
public Object servletRequest(HttpServletRequest request) {

}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :