多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
```java public class Category { @ManyToMany(targetEntity = Book.class, fetch = FetchType.EAGER) @JoinTable( //多对多查询将会添加一张中间表,该中间表SpringDataJpa会自动创建 name = "book_category_middle", //category_id 对应 Category.id 属性名,将会在中间表中存储 category_id 物理外键 joinColumns = {@JoinColumn(name = "category_id", referencedColumnName = "id")}, //book_id 对应 Book.id 属性名,将会在中间表中存储 book_id 物理外键 inverseJoinColumns = {@JoinColumn(name = "book_id", referencedColumnName = "id")} ) private List<Book> bookList; } ``` ```java public class Book { //bookList 对应 Category.bookList 属性名 @ManyToMany(mappedBy = "bookList", fetch = FetchType.EAGER) private List<Category> categoryList; } ``` >[warning] 如果你使用 lombok 请查看章节【注意事项】,了解一些细节。