简体   繁体   English

需要使用 spring 引导在数据库中创建表

[英]Need to create the Table in Database using spring boot

how can I create the work_with class in springBoot.如何在 springBoot 中创建work_with class。 I have tried my approch is that I have created the manytomany mapping between employee and client class but I was not able to create new colunm which is total_sales within work_with .我已经尝试过我的方法是我在员工和客户 class 之间创建了多对多映射,但我无法在 work_with 中创建新的列 total_sales Is there any way I can Create the new colunm during mapping and is my approch is right or wrong?有什么方法可以在映射期间创建新的列,我的方法是对还是错? if not what should I do to create the works_with table class/entity and also want to add ON DELETE CASCADE.如果不是,我应该怎么做才能创建works_with 表类/实体,并且还想添加ON DELETE CASCADE。

桌子

I want to create the Entity class just like I have done in below image.我想创建实体 class 就像我在下图中所做的那样。

@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<>();
    
        
}

You can find a lot of examples and articles online that explain how ManyToMany mappings work.您可以在网上找到很多解释多对多映射如何工作的示例和文章。 Just search with your favorite search engine for "JPA ManyToMany" and you will find an article like the following: https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany只需使用您最喜欢的搜索引擎搜索“JPA ManyToMany”,您就会找到类似以下的文章: https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM