当前位置: 首页 > 工具软件 > H2 > 使用案例 >

h2

璩涛
2023-12-01

1、建表语句:

drop table user if exists;
create table user(
    id bigint generated by default as identity,
    username varchar(40),
    name varchar(20),
    age int(3),
    balance decimal(10,2),
    primary key(id)
);

2、插入数据:

insert into user(id,username,name,age,balance) values(1, 'user1', 'tyy', 18, 100.00);
insert into user(id,username,name,age,balance) values(2, 'user2', 'zyy', 20, 100.00);
insert into user(id,username,name,age,balance) values(3, 'user3', '小周周', 1, 100.00);
insert into user(id,username,name,age,balance) values(4, 'user4', '小羊汤', 1, 100.00);

3、application.properties的配置:

spring:
  jpa:
    generate-ddl: false # 启动是否生成ddl语句
    show-sql: true  # 打印sql语句
    hibernate:
      ddl-auto: none  # jpa依赖hibernate,启动不做ddl语句处理
  datasource:
    platform: h2  # h2数据库
    schema: classpath:schema.sql  # 建表语句
    data: classpath:data.sql  # 表里的数据
  application:
    name: microservice-h2
    
logging:
  level:
    root: INFO  # 全局日志级别
    org.hibernate: INFO # hibernate日志级别,与下面两行一起表示显示sql语句同时打印参数
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
    org.hibernate.type.descriptor.sql.BasicExtractor: TRACE
    com.aerotop.microserviceh2: DEBUG

 

 类似资料: