將數(shù)據(jù)從React應(yīng)用程序發(fā)送到Spring Boot Controller時遇到了一個小問題,我通過put方法發(fā)送了數(shù)據(jù),但出現(xiàn)400錯誤,并且出現(xiàn)了eclipse錯誤,所以我要做的是:export const changeContratTypes = (idContrat, items, declaration) => { const endpoint = template(CONTRAT_TYPES_CHANGE); return instance // just an axios instance .put(endpoint({ idContrat }), { items, declaration }) .then(values => values) .catch(err => err.response);};我的端點常量是url,很簡單,我發(fā)送的聲明是整數(shù),而item是對象數(shù)組,我的對象結(jié)構(gòu)是:{ id: 1, // or 2, 3, .... isSelected: true, // or false title: "a String here" }為了在Spring Boot中得到這個,我在控制器中創(chuàng)建了這個方法:@CrossOrigin(origins = "*")@ApiOperation(value = "${contrat.recuperation}", notes = "${contrat.recuperation.notes}", response = ContratDetailDto.class)@PutMapping(value="/{idContrat}/trtype")@ApiModelProperty(example = "4000004")@ApiResponses(value = { @ApiResponse(code = 200, message = "Enrigistrer Les types de contrats ") })public ResponseEntity enrigistrerTypesDeContrat(@ApiParam(value = "${contrat.recuperation.param.id}") @PathVariable long idContrat, @RequestBody TypesConformites tcf) { if (log.isDebugEnabled()) { log.debug("appel de la méthode enrigistrerTypesDeContrat"); } System.out.println("Voila "+tcf.getDeclaration()); return ResponseEntity.ok(HttpStatus.OK);}該控制器映射良好,其他方法也可以正常工作,但是我使用的所有方法都是Get Methods。在此之前,我要做的是創(chuàng)建一個用作RequestBody的類:@Getter @Setterpublic class TypesConformites { private int declaration; private ArrayList<Item> items; public TypesConformites() { }} 這是我的Item類:@Getter @Setterpublic class Item { private int id; private String title; private boolean isSelected; public Item() { }}該代碼有什么問題,任何幫助將不勝感激。
無法將數(shù)組從JS獲取到我的Spring Boot控制器?
梵蒂岡之花
2021-05-02 12:09:15