5、数据库方面的操作

1345806-20180326103550497-2063163602.png
1345806-20180326103551730-1317904632.png
1345806-20180326103553767-142434701.png
使用数据库首先要pom文件当中添加两个依赖
  1. mysql-connector-java
  2. spring-boot-starter-data-jpa
  3. 然后创建数据实体
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;
    }
}
x
50
 
1
package com.girl;
2
 
            
3
import org.springframework.data.annotation.Id;
4
 
            
5
import javax.persistence.Entity;
6
import javax.persistence.GeneratedValue;
7
 
            
8
/**
9
 * Created by sunnyangzs on 2018/3/26.
10
 */
11
 
            
12
 
            
13
@Entity
14
public class Girl {
15
    @javax.persistence.Id
16
    @GeneratedValue
17
    private Integer id;
18
 
            
19
    private Integer age;
20
 
            
21
    private String cupSize;
22
 
            
23
    public Girl() {
24
    }
25
 
            
26
    public Integer getId() {
27
        return id;
28
    }
29
 
            
30
    public void setId(Integer id) {
31
        this.id = id;
32
    }
33
 
            
34
    public Integer getAge() {
35
        return age;
36
    }
37
 
            
38
    public void setAge(Integer age) {
39
        this.age = age;
40
    }
41
 
            
42
    public String getCupSize() {
43
        return cupSize;
44
    }
45
 
            
46
    public void setCupSize(String cupSize) {
47
        this.cupSize = cupSize;
48
    }
49
}
50
 
            
配置yml文件
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

1
16
 
1
spring:
2
  profiles:
3
    active: dev
4
 
            
5
  datasource:
6
    driver-class-name: com.mysql.jdbc.Driver
7
    url: jdbc:mysql://127.0.0.1:3306/dbgirl
8
    username: root
9
    password: nowcoder
10
 
            
11
  jpa:
12
    hibernate:
13
      ddl-auto: create
14
    show-sql: true
15
 
            
16
 
            
创建数据库
  1. dbgirl





转载于:https://www.cnblogs.com/sunnyangzs/p/8648624.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值