我在將數(shù)據(jù)從我的 React 應(yīng)用程序發(fā)送到我的 Spring Boot 控制器時(shí)遇到了一點(diǎn)問題,我通過 put 方法發(fā)送數(shù)據(jù),但是我得到 400,錯(cuò)誤,并且 eclipse 中彈出一個(gè)錯(cuò)誤,所以我所做的是: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);};我的端點(diǎn)常量是 url,很簡單,我發(fā)送聲明是一個(gè)整數(shù)和項(xiàng)目是一個(gè)對(duì)象數(shù)組,我的對(duì)象結(jié)構(gòu)是:{ id: 1, // or 2, 3, .... isSelected: true, // or false title: "a String here" }為了在 Spring Boot 中得到這個(gè),我在我的控制器中創(chuàng)建了這個(gè)方法:@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 方法。我之前所做的是創(chuàng)建一個(gè)用作 RequestBody 的類:@Getter @Setterpublic class TypesConformites { private int declaration; private ArrayList<Item> items; public TypesConformites() { }} 這是我的項(xiàng)目類:@Getter @Setterpublic class Item { private int id; private String title; private boolean isSelected; public Item() { }}
無法從 JS 獲取數(shù)組到我的 Spring 引導(dǎo)控制器?
呼喚遠(yuǎn)方
2022-10-12 09:53:06