每次编一些简单的应用总是要创建表,安装数据库非常繁琐

这里可以通过 H2 数据库的持久化功能来达到和Mysql一样功能,且不需要安装数据库非常便利

spring:
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:file:/www/${spring.application.name}/db
    # Windows
    # url: jdbc:h2:file:C:/data/sample/${spring.application.name}/db;
    username: sa
    password:
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.H2Dialect
  h2:
    console:
      path: /h2
      enabled: true
      settings:
        web-allow-others: true

把url 修改文件类型,然后设置spring.jpa.hibernate.ddl-auto=update

h2 的访问配置根据喜好来吧

参考

[1]. How to configure spring-boot to use file based H2 database . Avinash . https://stackoverflow.com/questions/37903105/how-to-configure-spring-boot-to-use-file-based-h2-database

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐