gpt4 book ai didi

java - JSON 解析错误 : Cannot deserialize instance of. 。超过 START_ARRAY token

转载 作者:行者123 更新时间:2023-12-01 17:38:52 25 4
gpt4 key购买 nike

我知道 stackoverflow 上有一些关于这个问题的问题。但我花了几个小时试图解决这个错误,但没有成功。

我使用 mysql 数据库来存储值。

我不断收到来自com.example.springboot.Recipe 文件。

这是 springboot 配方文件

package com.example.springboot;
import com.example.springboot.Recipe;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Entity // This tells Hibernate to make a table out of this class

public class Recipe {

public Recipe(){

}

public Recipe(Integer id, String name, String description, String type, Integer preptime, Integer cooktime, String content, Integer difficulty){
this.id = id;
this.name = name;
this.description = description;
this.type = type;
this.preptime = preptimee;
this.cooktime = cooktime;
this.content = content;
this.difficulty = difficulty;
}

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;


private String name;


private String description;


private String type;


private Integer preptime;


private Integer cooktime;


@Column(columnDefinition = "TEXT")
private String content;

private Integer difficulty;






public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitle() {
return name;
}

public void setTitle(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public Integer getDifficulty() {
return difficulty;
}

public void setDifficulty(Integer difficulty) {
this.difficulty = difficulty;
}

public Integer getCookingtime() {
return cooktime;
}

public void setCookingtimeime(Integer cooktime) {
this.cooktime = cooktime;
}

public Integer getPreparationtime() {
return preptime;
}

public void setPreparationtime(Integer preptime) {
this.preptime = preptime;
}
}

Main Controller:
@PutMapping("/recipes/edit/{id}")
void updateRecipe2(@PathVariable int id, @RequestBody Recipe recipe ) {

Recipe recipe_ = recipeRepository.findById(id).get();
recipe_.setTitle(recipe.getTitle());


System.out.println("sss " + recipe.getname());



System.out.println("change");
recipeRepository.save(recipe_);
}

服务.ts:

updateRecipe2 (id: number, recipe: any): Observable<any > {
const url = `${this.usersUrl}/edit/${id}`;
return this.http.put(url ,recipe);
}

调用 updateRecipe2 的位置:

 save(): void {
const id = +this.route.snapshot.paramMap.get('name');
this.recipeService.updateRecipe2(id, this.recipes)
.subscribe(() => this.gotoUserList());

}

一旦用户单击“保存”,此功能就会保存所做的更改。我希望我提供的代码片段足以帮助解决问题。预先感谢您。

我正在使用 Spring Boot 构建一个 REST API,并且使用 AngularJS 作为前端。我对网络开发还很陌生。

最佳答案

您正在向需要单个配方对象的 API 端点发送配方列表。

您的选择是:

  • 一次仅发送一个配方对象,例如:

    this.recipeService.updateRecipe2(id, this.recipes[0])
  • 或者:创建一个新的 API 端点来接受配方列表,并“批量”编辑它们

    @PutMapping("/recipes/edit")
    void updateRecipes(@RequestBody List<Recipe> recipe ) {

关于java - JSON 解析错误 : Cannot deserialize instance of. 。超过 START_ARRAY token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60997963/

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