springboot集成h2以及可視化操作


1.新建項目
 
2.設置配置文件:
 
#h2配置
#spring.jpa.show-sql = true #啟用SQL語句的日志記錄
#spring.jpa.hibernate.ddl-auto = update  #設置ddl模式
#數據庫的內容在最后一個連接關閉時丟失。如果要保留內容,必須像這樣配置URL
#spring.datasource.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
##數據庫連接設置
spring.datasource.url = jdbc:h2:mem:dbtest
#spring.datasource.username = sa  #配置數據庫用戶名
#spring.datasource.password = sa  #配置數據庫密碼
#spring.datasource.driverClassName =org.h2.Driver  #配置JDBC Driver
##數據初始化設置
#進行該配置后,每次啟動程序,程序都會運行resources/db/schema.sql文件,對數據庫的結構進行操作。
spring.datasource.schema=classpath:db/schema.sql
#進行該配置后,每次啟動程序,程序都會運行resources/db/data.sql文件,對數據庫的數據操作。
spring.datasource.data=classpath:db/data.sql
##h2 web console設置
#表明使用的數據庫平台是h2
spring.datasource.platform=h2
#spring.h2.console.settings.web-allow-others=true  # 進行該配置后,h2 web consloe就可以在遠程訪問了。否則只能在本機訪問。
#進行該配置,你就可以通過YOUR_URL/h2訪問h2 web consloe。YOUR_URL是你程序的訪問URl。
spring.h2.console.path=/h2
#spring.h2.console.enabled=true  #進行該配置,程序開啟時就會啟動h2 web consloe。當然這是默認的,如果你不想在啟動程序時啟動h2 web consloe,那么就設置為false。
spring.h2.console.enabled=true
3.建表插入數據
 
4.在瀏覽器中訪問
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM