springboot create entity classes and generate database table

  1. Need to mark the entity class represents the entity class @Entity
  2. @Table (name = "t_tag") is generated to represent the table name t_tag
  3. @Id represents the primary key
    @GeneratedValue represent the primary key is automatically incremented
    two notes need to be noted on the primary key id
  4. How to represent the links between objects?
    Such as a blog and a blog classification is many relationship between
    1) needs to be added in the blog category.
    The @ManyToOne ()
    Private the Type type;
    . 2) in the need to add a blog category
    @OneToMany (the mappedBy = "type")
    Private Blogs = new new ArrayList List <> ();
    . 3) Note:
    the mappedBy = "of the type" need to write a reprint of this end, showing the relationship is ... to maintain
  5. Add need to reprint entity class constructor with no arguments, get, set method, toStriing method (toString method for facilitating output to the log)
  6. Add the following information in the file application.yml
  jpa:
    hibernate:
      #      每次启动项目的时候 自动判断 
      # 项目中的实体类与数据库中的表结构是否一样,如果不一样的时候 
      # 需要重新创建 实体生产环境中 将下面的 ddl-auto设置为none
      ddl-auto: update
  	  #      将sql语句显示在控制台
  	  show-sql: true
	  #    配置日志

  1. The final table will generate entity classes with some other object is generated according to the relationship table
    Here Insert Picture Description
Published 43 original articles · won praise 13 · views 4892

Guess you like

Origin blog.csdn.net/qq_30693057/article/details/100814157