版权声明:未经允许,不得转载 https://blog.csdn.net/kangkanglou/article/details/84061892
H2 is one of the popular in memory databases.
H2 is a relational database management system written in Java. It can be embedded in Java applications or run in the client-server mode.
添加H2 POM依赖
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
创建Student实体
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Student {
@Id
@GeneratedValue
private Long id;
private String name;
private String passportNumber;
}
启用H2 Web Console
# Enabling H2 Console
spring.h2.console.enabled=true
SpringBoot中H2 DataSource配置
# DataSource Configuration
spring.datasource.url=jdbc:h2:mem:cib
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql = true
启动应用程序,访问H2 Web Console:http://localhost:8090/h2-console
数据库查询
http://www.springboottutorial.com/spring-boot-and-h2-in-memory-database