• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Loneliness Ends HUHU
热情坦诚
博客园    首页    新随笔    联系   管理    订阅  订阅
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;
    }
}

 

 

posted on 2018-04-16 19:18  meiLinYa  阅读(385)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3