通过服务jsonschema2pojo.org/创建了一个dto类来处理json。结果是一个包含其他类的类,例如:
public class GeneralExmp{
private Strig name;
// GetAndSet
public class Exmp2{
private Strig id;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
// GetAndSet
}
public class Exmp3{
private Strig val;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
// GetAndSet
}
}
现在需要创建一个方法,从这个类中提取所需的值。例子:
让我们创建一个类:
public class Params {
public Params() {
}
public Params(String name, String val) {
this.name = name;
this.val = val;
}
private String name;
private String val;
// GetAndSet
}
json获得的类:
@Service
public class InstrumentGetService {
RestTemplate restTemlate;
public List<Params> getInfo(String token,
String order) {
final var url = String.format(
"https://example.ru/rest/getOrderStatus.do?token=%s&orderId=%s", token, order);
GeneralExmp dto = restTemlate.getForObject(url, GeneralExmp.class);
return Collections.singletonList(toModel(dto));
}
以及显示所需参数的方法:
public Params toModel(GeneralExmp dto) {
//??
return new Params(//? , //?);
}
告诉我如何正确实现tomodel方法?我无法将get和set从exmp类获取到params构造函数中
暂无答案!
目前还没有任何答案,快来回答吧!