设为首页 加入收藏

TOP

Spring Boot 使用 H2 内存数据库
2019-05-11 01:35:51 】 浏览:48
Tags:Spring Boot 使用 内存 数据库
版权声明:未经允许,不得转载 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 Consolehttp://localhost:8090/h2-console
在这里插入图片描述

数据库查询
在这里插入图片描述


http://www.springboottutorial.com/spring-boot-and-h2-in-memory-database
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于HBASE里的一个问题 下一篇ArcGIS for Android地图控件常见..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目