我最近一直在開發一個 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 networkspublic 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;@Repositorypublic interface ProductRepository extends JpaRepository<Product,Long> {}
1 回答

慕標琳琳
TA貢獻1830條經驗 獲得超9個贊
@Controller只需在控制器上設置as 注釋即可。
//imports
@Controller
public class ProductRestController {
? ? @Autowired
? ? ProductService productService;
? ? //GetMapping etc
}
@RestController您也可以使用注釋。
添加回答
舉報
0/150
提交
取消