這章介紹Spring Boot JPA 訪問H2 Database得滤,在項目開發(fā)過程中都會連接本地數(shù)據(jù)庫進行業(yè)務(wù)開發(fā)與數(shù)據(jù)驗證,這個時候使用H2 就顯得輕便與實用了盒犹,在生產(chǎn)線上也可把他當來數(shù)據(jù)庫或內(nèi)存數(shù)據(jù)來使用懂更。下文開始演示H2的使用。
H2 Database 優(yōu)點介紹:
Welcome to H2, the Java SQL database. The main features of H2 are:
Very fast, open source, JDBC API
非臣卑颍快沮协,開源,JDBC API
Embedded and server modes; in-memory databases
嵌入式和服務(wù)器模式卓嫂;內(nèi)存數(shù)據(jù)庫
Browser based Console application
基于瀏覽器的控制臺應(yīng)用程序
Small footprint: around 1.5 MB jar file size
約1.5 MB JAR文件大小
官網(wǎng)下載
http://h2database.com/html/main.html
請根據(jù)自身環(huán)境下載:
Paste_Image.png
本地安裝后啟動:
Paste_Image.png
請選擇自已熟悉的語言與登錄模式
引入依賴
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
修改application.properties配置
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
完成后慷暂,直接使用 **Spring Boot JPA訪問Mysql **,中的UserTest.java進行單元測試,不需要做任何修改
http://www.reibang.com/writer#/notebooks/10854929/notes/10190080
如圖:
Paste_Image.png
Paste_Image.png
登錄H2 數(shù)據(jù)庫驗證數(shù)據(jù)正確性:
Paste_Image.png