Spring Boot H2的基础知识
H2数据库
必需的 Spring 依赖
-
- H2 Database
-
- JDBC API
-
- Spring Web
- Spring Boot Devtools(you shoud install if you need.)
由于更喜欢使用yml文件编写配置,所以在这里我选择在yml文件中编写配置,而不是在application.properties文件中编写。
// application.properties(個人的に嫌い。。。)
spring.datasource.url=~
spring.datasource.username=~
// mem(メモリ)=Springを起動するたびに初期化される。
spring:
datasource:
url: jdbc:h2:mem:test
driverClassName: org.h2.Driver
// 管理者権限
username: sa
password:
// Webブラウザから確認できるようにする。
h2.console.enabled: true
我认为在此状态下,可以访问localhost:8080/h2-console。
在开发中,我们将首先创建一个虚拟数据库,并将数据存入其中,然后使用该数据库。我们将继续处理这部分工作。
只需要在这里创建并部署SQL语句~。
这次准备了两个文件。
-
- scheme.sql
- data.sql
// scheme.sql
create table music(
id int not null auto_increment,
bandName varchar(100) not null,
bestSong varchar(100) not null,
created datetime not null,
primary key(id)
);
// data.sql
insert into music (bandName,bestSong,created) values('Queen', 'We Will Rock You', '2019-11-12 08:34:19');
