gpt4 book ai didi

javascript - 保存对象列表返回 Cannot deserialize 错误

转载 作者:行者123 更新时间:2023-12-02 11:04:09 25 4
gpt4 key购买 nike

我使用 Spring Boot 和 thymeleaf我尝试保存对象列表。

我的对象。

public class GECPD {
public Integer id;
public String name;
public List<GEPD> geL;
public Integer giId;
public Integer sGEId;
}

在我的 Controller 中,我返回一个对象列表

  Set<GECPD> gECL = new HashSet<>();
...
model.addAttribute("gECL", new ArrayList<>(gECL));

数据显示正确

<input name="id[0]" type="hidden" value="136">
<select name="sGEId[0]" class="form-control">
<option value="246">01</option>
<option value="391">00</option>
</select>

我的 Controller

  @PutMapping(value = "/{id}/ge")
public ResponseEntity updateGE(@PathVariable("id") Integer id, @RequestBody List<GECPD> dto) {
....
return new ResponseEntity(dto,HttpStatus.OK);
}

函数 saveGroundElement(){

var form = transForm.serialize('#gEForm');
var url = "/rest/spi/" + $("#spi").val() + "/ge";
form = JSON.stringify(form);
jQuery.ajax({
type: "put",
url: url,
contentType: "application/json",
data: form,
success: function (data, status, jqXHR) {
},
error: function (jqXHR, status) {

checkError(jqXHR);
}
});

}

数据发送

{"id":["136"],"sGEId":["246"]}

我得到这个结果

Erreur: { "timestamp" : "2018-06-29T15:36:58.427+0000", "status" : 400, "error" : "Bad Request", "message" : "JSON parse error: Cannot deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]", "path" : "/rest/spi/1/ge" }

有什么想法吗?

最佳答案

你的前端没问题...你需要修改你的服务器端

@PutMapping(value = "/{id}/ge")
public ResponseEntity updateGE(@PathVariable("id") Integer id, @RequestBody GECPDList dto) {
....
return new ResponseEntity(dto,HttpStatus.OK);
}

在 GECPDS 中

public GECPDList class{
private List<GECPD> gecpds;
}

关于javascript - 保存对象列表返回 Cannot deserialize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51105759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com