@@@@@@@@@@@@@@@@@@@]

问题描述 投票:0回答:1
我将@Request字符串用于Post API的有效负载,如下所示:

@PutMapping("/{account}/accountid") public ResponseEntity<Account> createAccount(@Valid @RequestBody String payload) { ......... //Later converting this String to pojo based on some condition }

我知道应该使用Pojo代替@RequestBody,而不是String,但是现在需要更改设计。如果我将有效负载用作@RequestBody的String的话,这有什么坏处?字符串有效负载如下所示:

{ "account": { "id": "1001", "name": "....", "test": ".........." }, "test": { "testing":"..." } }

我正在使用@Request字符串作为Post API的有效负载,如下所示:@PutMapping(“ / {account} / accountid”)public ResponseEntity 

createAccount(@Valid @RequestBody字符串有效负载){......] >

spring-boot spring-mvc spring-data spring-restcontroller
1个回答
0
投票
为什么不为传入的数据创建DTO pojo类并将其映射到内部实体,也可以使用诸如ModelMapper或MapStruct之类的可自动处理转换的库。
© www.soinside.com 2019 - 2024. All rights reserved.