亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從 JS 獲取數組到我的 Spring 引導控制器?

無法從 JS 獲取數組到我的 Spring 引導控制器?

呼喚遠方 2022-10-12 09:53:06
我在將數據從我的 React 應用程序發送到我的 Spring Boot 控制器時遇到了一點問題,我通過 put 方法發送數據,但是我得到 400,錯誤,并且 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,很簡單,我發送聲明是一個整數和項目是一個對象數組,我的對象結構是:{    id: 1, // or 2, 3, ....   isSelected: true, // or false   title: "a String here"       }為了在 Spring Boot 中得到這個,我在我的控制器中創建了這個方法:@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 方法。我之前所做的是創建一個用作 RequestBody 的類:@Getter @Setterpublic class TypesConformites {   private int declaration;   private ArrayList<Item> items;    public TypesConformites() {   }} 這是我的項目類:@Getter @Setterpublic class Item {   private int id;   private String title;   private boolean isSelected;   public Item() {   }}
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊


通常,該項目由杰克遜反序列化,如下所示:-


public void setId(String firstName) {


public void setTitle(String lastName) {


public void setSelected(boolean isActive) {

為避免這種情況,您可以更改項目和請求正文中的映射名稱.. 或用您的 isSelected 注釋@JsonProperty


查看完整回答
反對 回復 2022-10-12
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號