SpringBoot 中使用 H2 数据库

1、加入POM

1 <!-- https://mvnrepository.com/artifact/com.h2database/h2 --> 2 <dependency> 3 <groupId>com.h2database</groupId> 4 <artifactId>h2</artifactId> 5 <version>1.4.200</version> 6 </dependency> 7 8 <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter --> 9 <dependency> 10 <groupId>com.baomidou</groupId> 11 <artifactId>mybatis-plus-boot-starter</artifactId> 12 <version>3.0.7</version> 13 </dependency>

2、配置 application.properties

1# spring h2 database configuration 2spring.h2.console.enabled=true 3spring.h2.console.path=/h2 4spring.datasource.driver-class-name=org.h2.Driver 5spring.datasource.url=jdbc:h2:mem:mytest;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false 6spring.datasource.username=sa 7spring.datasource.password=sa 8spring.datasource.schema-username=sa 9spring.datasource.schema-password=sa 10spring.datasource.data-username=sa 11spring.datasource.data-password=sa 12spring.datasource.schema=classpath:database/schema_*.sql 13spring.datasource.data=classpath:database/data_*.sql 14spring.datasource.initialization-mode=always 15spring.jmx.enabled=false 16 17 18# mybatis-plus 19mybatis-plus.global-config.banner=false 20mybatis-plus.global-config.db-config.id-type=auto 21mybatis-plus.global-config.db-config.field-strategy=not_empty 22mybatis-plus.global-config.db-config.table-underline=true 23mybatis-plus.global-config.db-config.db-type=h2 24mybatis-plus.global-config.db-config.logic-delete-value=1 25mybatis-plus.global-config.db-config.logic-not-delete-value=0

3、设置schema和data文件

1schema: 2DROP TABLE IF EXISTS t_base_user; 3 4CREATE TABLE t_base_user 5( 6 id INT(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 7 user_name VARCHAR(255) NULL DEFAULT NULL COMMENT '用户姓名', 8 create_time DATETIME NULL DEFAULT NULL COMMENT '创建时间', 9 PRIMARY KEY (id) 10); 11 12 13data: 14DELETE FROM t_base_user; 15 16INSERT INTO t_base_user (user_name, create_time) VALUES 17('Jone', now()), 18('Jack', now()), 19('Tom', now()), 20('Sandy', now()), 21('Billie', now());

4、实体、Mapper、Service

1@ApiModel(value = "用户实体") 2@Data 3@NoArgsConstructor 4@AllArgsConstructor 5@TableName("t_base_user") 6public class User implements Serializable { 7 8 @ApiModelProperty(value = "主键") 9 @TableId(value = "id", type = IdType.NONE) 10 private Long id; 11 @ApiModelProperty(value = "姓名") 12 private String userName; 13 @ApiModelProperty(value = "创建时间") 14 private Date createTime; 15} 16 17 18@Mapper 19public interface UserMapper extends BaseMapper<User> { 20} 21 22public interface UserService extends IService<User> { 23} 24 25 26@Service 27@Transactional 28public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { 29}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

swap空间的增减方法

(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap