5、数据库方面的操作

  1. 使用数据库首先要pom文件当中添加两个依赖
    1. mysql-connector-java
    2. spring-boot-starter-data-jpa
    3. 然后创建数据实体
      1. package com.girl;
        
        import org.springframework.data.annotation.Id;
        
        import javax.persistence.Entity;
        import javax.persistence.GeneratedValue;
        
        /**
         * Created by sunnyangzs on 2018/3/26.
         */
        
        
        @Entity
        public class Girl {
            @javax.persistence.Id
            @GeneratedValue
            private Integer id;
        
            private Integer age;
        
            private String cupSize;
        
            public Girl() {
            }
        
            public Integer getId() {
                return id;
            }
        
            public void setId(Integer id) {
                this.id = id;
            }
        
            public Integer getAge() {
                return age;
            }
        
            public void setAge(Integer age) {
                this.age = age;
            }
        
            public String getCupSize() {
                return cupSize;
            }
        
            public void setCupSize(String cupSize) {
                this.cupSize = cupSize;
            }
        }
        
    4. 配置yml文件
      1. spring:
          profiles:
            active: dev
        
          datasource:
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://127.0.0.1:3306/dbgirl
            username: root
            password: nowcoder
        
          jpa:
            hibernate:
              ddl-auto: create
            show-sql: true
        
        
    5. 创建数据库
      1. dbgirl





posted @ 2018-03-26 09:11  sunnyangzs  阅读(120)  评论(0编辑  收藏  举报