【发布时间】:2018-05-23 10:09:30
【问题描述】:
在 Spring BOOT 应用程序中开发 REST 服务。
这是输入的json
{
"rcode": 122,
"ecode": [11, 12]
}
控制器代码
@RequestMapping("/getPersonDTOList")
public List < PersonDTO > getPersonDTOList(
@RequestParam(value = "personDTO") String personDTO){
//how can I map this to DTO
}
//DTO
public class PersonDTO {
private Int rcode;
private List<Int> ecode;
}
如何在 spring BOOT 中将此字符串映射到 DTO,由于这是 GET,我们需要手动执行。
【问题讨论】:
-
为什么不是POST?
-
@SudhirOjha 可能是因为请求没有改变服务器上的任何东西(即数据库)
-
你如何将 json 传递给 rest-service?
-
@Abhijeet 我也可以将其作为请求参数传递,无需作为请求正文发送。
标签: spring spring-boot