Spring Boot 无法从 MySQL 数据库中获取和显示数据

我最近一直在开发一个 Spring Boot 项目,该项目以 JSON 格式更新和从 MySQL 数据库中获取数据,但是当我运行我的应用程序时,我有一个错误页面:

[我浏览器上的错误截图][1] [1]: https://i.stack.imgur.com/CkYmr.png

我的实体类是:

package com.project.project.entities;


import javax.persistence.*;

import java.io.Serializable;

import java.util.List;


@Entity

@Table(name = "products")

// why serializable ?? every entity in JPA is automatically-serializable,  connection between different networks

public class Product implements Serializable {

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY) // assign a unique value to your identity field automatically

    private Long id;

    private String designation;

    private int price;

    private int quantity;

    private int category_id;


    // the owning side of the relationship, side of the foreign key


    @ManyToOne(fetch = FetchType.LAZY )// many products to one category

    @JoinColumn(name = "category_id" , insertable = false , updatable = false)

    // means that the product table will have a fk_column named...

    private Category category;



    // categoryId foreign key referencing to the primary key on Category

    // Double and Integer in case both variables are unknown -> Category constructor

    public Product(Long id, String designation, Integer price, Integer quantity, int categor_id) {

        this.id = id;

        this.designation = designation;

        this.price = price;

        this.quantity = quantity;

        this.category_id = category_id;

    }

我的存储库:


import com.project.project.entities.Product;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.stereotype.Repository;



@Repository

public interface ProductRepository extends JpaRepository<Product,Long> {


}


吃鸡游戏
浏览 143回答 1
1回答

慕标琳琳

@Controller只需在控制器上设置as 注释即可。//imports@Controllerpublic class ProductRestController {    @Autowired    ProductService productService;    //GetMapping etc}@RestController您也可以使用注释。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java