快速搭建基于H2&SpringBoot项目

创建项目(IDEA)
  • File > New Project > Spring Initializr(jdk1.8) > Next Project Settings(java version1.8) > Next Dependencies(Web: Spring Web, SQL: H2&Spring Data JPA)

  • Configure application.yaml(修改application.properties格式)

      server:
        port: 8099
        servlet:
          context-path: /auto-gen
    
      spring:
        application:
          name: auto-gen
        datasource:
          url: jdbc:h2:F:/H2/db/db02
          username: root
          password: root
          driverClassName: org.h2.Driver
          schema: classpath:db-assets/schema.sql
          platform: h2
        h2:
          console:
            settings:
              web-allow-others: true
            path: /h2
            # 开启浏览器访问
            enabled: true 
    
  • Configure db

    -- edit db-assets/schema.sql, for example: 
    create table if not exists ADMIN_ACC (
    USER_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    USER_NAME VARCHAR(100)
    );
    
    
启动项目
  • Run AutoGenerationApplication.java

  • 访问H2数据库控制台

    http://localhost:8099/auto-gen/h2

    JDBC URL: jdbc:h2:F:/H2/db/db02 #与上面配置spring.datasource.url同

    User Name: root

    Password: root

源代码地址: https://download.csdn.net/download/weixin_49689128/12670271

你可能感兴趣的:(SpringBoot,H2,数据库,java)