本文介绍:spring boot 使用数据库范例
H2 内存数据库
1 pom.xml 添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
2 配置属性:
jpa:
show-sql: true
hibernate:
ddl-auto: update
datasource:
data-username: sa
data-password: 123456
driver-class-name: org.h2.Driver
url: jdbc:h2:./test;;AUTO_SERVER=TRUE
h2:
console:
path: /h2-console
enabled: true
3 添加对象模型
package com.demo.reid.entity;
import javax.persistence.Entity;
import javax.persistence.Gene