zoukankan      html  css  js  c++  java
  • spring--boot数据库连接以及class建表

          Spring-Boot  数据库连接以及class建表

       

      提前在pom.xml文件中添加:jpa,mysql资源

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>

      数据库连接:

    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/dbgirl
        username: root
        password: root
      jpa:
        hibernate:
          ddl-auto: create   //每次程序运行时都建新建一个girl表:如果原来有就删除原来的表,再建一个新的
        show-sql: true

      create:

        

      update:只进行更新

      create-drop:才程序停下来就会删掉表

      none:什么都不做

      validate:验证表中与类中的,不一致则会报错  

      写一个class文件:

    package com.girl;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    
    @Entity
    public class girl {
    
        @Id
        @GeneratedValue
        private Integer id;
        private String cupSize;
        private Integer age;
    
        public girl() {
        }
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getCupSize() {
            return cupSize;
        }
    
        public void setCupSize(String cupSize) {
            this.cupSize = cupSize;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    }

     

  • 相关阅读:
    38) 收集centos所有版本镜像下载地址
    37) 查看linux 操作系统为多少位
    php面向对象高级应用一
    php form表单的验证+提交到数据库
    php获取form表单数据
    php form表单的提交
    php form表单概念
    php日期和时间的应用
    php日期和时间函数
    php字符串函数操作实例(2)
  • 原文地址:https://www.cnblogs.com/meiLinYa/p/8857975.html
Copyright © 2011-2022 走看看