我想保存来自一个api的json响应的参数,以便移交给另一个api。另一个api应该接收帐户余额,并说明客户是否有正余额或负余额。
json码:
id: 1
name: "Lars"
lastname: "Günther"
birth: "1995-10-10"
sex: "m"
road: "Bahnhofsstrasse 17"
town: "Borken"
account:
0:
bankaccNr: 3
customerstatus: "private client"
accountbalance: -3127
openingdate: "2001-01-23"
iban: "DE37500105174133576347"
1:
bankaccNr: 16
customerstatus: "corporate client"
accountbalance: 71764
openingdate: "2014-07-09"
iban: "DE09500105177725527397"
postalcode: 46325
这就是我调用这个api时得到的json。0和1不是模型的一部分。当此帐户Map到客户时,它们将自动生成。
客户:
@ManyToMany(targetEntity = Account.class, mappedBy = "customer", cascade = CascadeType.ALL)
private Set<Account> account= new HashSet<>();
public Customer() {}
public Customer(String name, String lastname, Date birth, char sex, String road, int postalcode, String town) {
this.name=name;
this.lastname=lastname;
this.birth=birth;
this.sex=sex;
this.road=road;
this.postalcode=postalcode;
this.town=town;
}
//getters/setters...
我应该将它保存为对象还是哈希Map。如何处理此对象?如果一个客户有多个帐户怎么办?
@RequestMapping(value = { "/{id}/liquid" }, method = RequestMethod.GET)
public Konto getLiquid(@PathVariable(value = "id") Long customer_id){
String url = "http://localhost:8081/mybank/customer/data/{id}";
Customer customer= restTemplate.getForObject(url, Kunde.class,kundeid);
'object or hashmap?'
HashMap <String,Map> answer= restTemplate.getForObject(url, new HashMap<>().getClass(),kundeid);
String urlForServiceB = "http://localhost:8082/liquicontroller/liquiditat/{value}";
int firstvalue = ???
// get http response --> true or false
return restTemplate.getForObject(urlForServiceB, String.class,firstvalue);
}
如何向其他api发送多个请求?
1条答案
按热度按时间tct7dpnv1#
客户应该有一个帐户列表。如果根据您的业务需求,如果是多对多Map,那么帐户应该有客户列表。
从上面看,它看起来像每个客户有许多帐户,所以我们可以在客户的帐户列表
resttemplate将json从实体Map到您的客户。
对于上述工作响应,应在客户中包含嵌套列表。如果没有这种情况,那么下面必须为每个帐户id反复调用