【问题标题】:Need to create the Table in Database using spring boot需要使用spring boot在数据库中创建表
【发布时间】:2022-08-15 16:59:48
【问题描述】:

我怎样才能创建work_withSpring Boot 中的类。我试过我的方法是我已经在员工和客户类之间创建了多对多映射,但我无法在 work_with 中创建 total_sales 的新列.有什么方法可以在映射期间创建新列,我的方法是对还是错?如果不是,我应该怎么做才能使用表类/实体创建作品以及想要添加 ON DELETE CASCADE。

我想创建 Entity 类,就像我在下图中所做的那样。

@Entity
@Table(name=\"posts\")
@NoArgsConstructor
@Getter
@Setter
public class **Post** {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    
    @Column(name=\"post_tittle\",length = 100, nullable = false)
    private String tittle;
    
    @Column(name=\"post_image\", nullable = false)
    private String imageName;
    
    private String content;
    
    private Date addedDate;
    
    
    @ManyToOne
    @JoinColumn(name=\"category_id\")
    private Category category;
    
    
    @ManyToOne
    private User user;
    
    
    @OneToMany(mappedBy = \"post\",cascade = CascadeType.ALL)
    private Set<Comment> comments = new HashSet<>();
    
        
}

    标签: java spring spring-boot hibernate jsp


    【解决方案1】:

    您可以在网上找到很多解释多对多映射如何工作的示例和文章。只需使用您喜欢的搜索引擎搜索“JPA ManyToMany”,您就会找到类似以下的文章:https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 2018-12-30
      • 2021-10-30
      • 2016-10-21
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多