не может выполнить инструкцию; SQL [н / д]; Вложенным исключением является org.hibernate.exception.DataException: - PullRequest
0 голосов
/ 13 апреля 2020

Я пытаюсь установить для избранного значение true. Затем я буду использовать запрос get, чтобы получить все рецепты, для которых столбец favourite имеет значение true. В mysql верстаке я вижу, что значение столбца избранное определяется как TINYBLOB. Но когда я использую почтальон с путем http://localhost:8080/demo/recipes/favorize/2 a json, который выглядит следующим образом: {"favourite": "0"} я получаю сообщение об ошибке SQL [n \ a].

Кто-нибудь знаете, что я делаю не так? Это даже правильный подход?

Главный контроллер:

package com.example.springboot;
import com.example.springboot.Recipe;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:4200")
@Controller // This means that this class is a Controller
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
public class MainController {
    @Autowired // This means to get the bean called userRepository
    // Which is auto-generated by Spring, we will use it to handle the data
    private RecipeRepository recipeRepository;

    @GetMapping("/recipes")
    public List<Recipe> getRecipes() {
        System.out.println("enter");
        List<Recipe> recipe_list = (List<Recipe>) recipeRepository.findAll();
       if(recipe_list.isEmpty())
           System.out.println("Ist leer");

       return recipe_list;

    }


    @PutMapping("/recipes/favorize/{id}")
    void favorize(@PathVariable int id, @RequestBody Bool favorite) {
        System.out.println("entering");
        Recipe recipe_ = recipeRepository.findById(id).get();
        recipe_.setFavorite(favorite);
        System.out.println("enter");
        recipeRepository.save(recipe_);
    }

    @GetMapping("/recipes/favorites")
    public List<Recipe>  listFavorites() {
        System.out.println("entering list List");
        List<Recipe> recipe_list = (List<Recipe>) recipeRepository.findByFavorite(true);
        if(recipe_list.isEmpty())
            System.out.println("empty");

        return recipe_list;

    }




}

Рецепт. java:

package com.example.springboot;

import com.sun.org.apache.xpath.internal.operations.Bool;

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 title, String description, String type, Bool favorite){
        this.id = id;
        this.title = title;
        this.description = description;
        this.type = type;
        this.favorite = favorite;
    }

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

    //@NotBlank
    private String title;

    //@Column(columnDefinition = "TEXT")
    //@NotBlank
    private String description;

    //@NotBlank
    private String type;


    //@NotBlank
    @Column(columnDefinition = "TEXT")


    private Bool favorite;






    public Integer getId() {
        return id;
    }

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

    public String getTitle() {
        return title;
    }

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

    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 void setFavorite(Bool favorite) {this.favorite = favorite;}

    public Bool getFavorite() {return this.favorite;}

}
...