我有有效载荷 1、有效载荷 2 和有效载荷 3 的 DTO。如何获得有效载荷3?使用payload 1和payload 2。如何建立数据模型之间的映射关系?
DTO 1
public class DataRequestModel {
private DataValue data; //some example
private long timestamp;
@Data
public static class DataValue {
private Value1 value1;
private Value2 value2;
}
@Data
public static class Value1 {
private long val;
}
@Data
public static class Value2 {
private long val;
}
}
数据模型 2
public class Guid{
private string guid;
}
数据模型 3
public class payload{
private String guid;
private long longvalue;
private long timestamp;
}
## Controller
@RestController
@RequestMapping("/users")
public class DataTransferController {
List<Payload> payload;
@PostMapping("/list")
public void data(@RequestBody DataRequestModel dataRequestModel){
不知道从这里怎么做...
for(Payload temp: payload){
temp.getLongValue()=dataRequestModel.getData().
}
}
}
这些是 JSON 1.JSON payload1的结构
{
"data":{
"value1":{
"val":30
}, "value2":{
"val":20
}
},
"timestamp":155501523
}
2.JSON有效载荷2
{
"guid":[
"/value1",
"/value2"
]
}
3.JSON最终payload(待发送)
[
{
"guid":"/value1",
"longvalue":30,
"timestamp":155501523
},
{
"guid":"/value2",
"longvalue":20,
"timestamp":155501523
}
]
我生成有效载荷 3 的代码是
@RestController @RequestMapping("/users")
public class DataTransferController
{
List<Payload> payload; @PostMapping("/list")
public void data(@RequestBody DataRequestModel dataRequestModel)
{
Not sure how to do from here... for(TimeseriesPayload temp: timeseriesPayload)
{
temp.getLongValue()=dataRequestModel.getData().
}
}
}
慕丝7291255
相关分类