【发布时间】:2018-02-18 07:52:21
【问题描述】:
我是 Spring Boot 新手,我很难理解如何传递数据。例如:
我想将这些数据传递给我的服务器:
{
"code", 1,
"name": "C01"
}
所以我创建了 always 一个自定义对象,其中包含代码和名称作为属性来拥有这个 http post api?
@RequestMapping(value = "/new/", method = RequestMethod.POST)
public ResponseEntity<?> createOrder(@RequestBody CustomObject customObject){
...
}
我看到的另一个解决方案可能是这样,但我不能传递数字(int 代码),对吧?
@RequestMapping(value = "/new/{code}/{name}", method = RequestMethod.POST)
public ResponseEntity<?> createOrder(@PathVariable("code") int code, @PathVariable("name") String name) {
...
}
亲切的问候:)
【问题讨论】:
标签: spring spring-mvc spring-boot http-post spring-restcontroller