私はSpringBootでアプリケーションを持っています。私は取得していたURLを呼び出そうとするとスプリングブート - 奇妙なJSONコントローラの応答
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL, mappedBy = "client")
public List<Posto> getPosti() {
return posti;
}
public void setPosti(List<Posto> posti) {
this.posti = posti;
}
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL, mappedBy = "client")
public List<Luce> getLuci() {
return luci;
}
public void setLuci(List<Luce> luci) {
this.luci = luci;
}
:
@RestController
public class ClientController {
private static final Logger logger = Logger.getLogger(ClientController.class);
@Autowired ClientService clientService;
@RequestMapping(value = "/client", method = RequestMethod.GET)
public ResponseEntity<Client> getClient(@RequestParam(value = "idClient") int idClient)
{
Client client = clientService.findById(idClient);
return new ResponseEntity<Client>(client, HttpStatus.OK);
}
Client.javaは、このように注釈付きの2つのOneToManyフィールド、ルーチェとPOSTOを、持っている: 私は、単純なRestControllerを持っていますレスポンスの奇妙な振る舞い。 私は2つのPostoと2つのLuciオブジェクトを持っているとしましょう。 ポストオブジェクトはidClient = 1にリンクされ、1つのLuceのみがidClient = 1にリンクされます。 だから私は、例えば、ヒットした場合、http://localhost:8080/client?idClient=1
私は2 POSTOと1ルーチェを取得する必要がありますが、私は次の応答(私は簡潔のために、いくつかの重要でないフィールドを削除)を取得:だから私は2を取得しています
{
"idClient": 1,
"posti": [
{
"idPosto": 1,
"numeroPosto": 61,
"nomePosto": "Posto numero 61"
},
{
"idPosto": 2,
"numeroPosto": 152,
"nomePosto": "Posto numero 62"
}
],
"luci": [
{
"idLuce": 1,
"numeroLuce": 1,
"nomeLuce": "Lampada 1",
},
{
"idLuce": 1,
"numeroLuce": 1,
"nomeLuce": "Lampada 1",
}
]
}
を同じLuceオブジェクトを倍にします。それは私の状況が逆転していることも起こります、2 Luceと1 Posto、私は2倍の唯一のPostoを得ています。 PostoおよびLuceのすべてのオブジェクトがidClient 1にリンクされている場合、レスポンスは良好で、IDClientにLuce(またはPostoなし)がない場合でも良好です... どこから見てもわかりませんが、すべてが動作しているようSet
オブジェクトがdublicateを取らないので、私はClient.java
クラスで
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL, mappedBy = "client")
public Set<Posto> getPosti() {
return posti;
}
public void setPosti(Set<Posto> posti) {
this.posti = posti;
}
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL, mappedBy = "client")
public Set<Luce> getLuci() {
return luci;
}
public void setLuci(Set<Luce> luci) {
this.luci = luci;
}
を設定し、(Client.java
クラスhascodeを実装するエラー...
作業していませんでした... – besmart