背景
官方快速开始文档:
MyBatis-Plus快速开始
基于官方快速开始文档里踩得一些坑做一个简单的总结。
applicaion.properties配置问题
官方使用的是application.xml, 不习惯我使用的是applicaion.properties
文件结尾由.xml 换成 .properties
配置内容由 : 换成 .
server.port=8088
spring.datasource.url=jdbc:h2:mem:test;NON_KEYWORDS=USER;OLD_INFORMATION_SCHEMA=TRUE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=user
spring.sql.init.schema-locations=classpath:db/schema-h2.sql
spring.sql.init.data-locations=classpath:db/data-h2.sql
h2版本问题
h2最新的版本报错
[42S02][42102] org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CATALOGS" not found; SQL statement: select CATALOG_NAME from INFORMATION_SCHEMA.CATALOGS [42102-206]
解决方法:在xml文件里添加以下内容
OLD_INFORMATION_SCHEMA=TRUE
找不到启动sql文件
org.springframework.jdbc.BadSqlGrammarException: Error querying database. Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER" not found (this database is empty);
解决方法:在xml文件里添加以下内容
spring.sql.init.schema-locations=classpath:db/schema-h2.sql
spring.sql.init.data-locations=classpath:db/data-h2.sql
pom文件问题
com.baomidou.mybatisplus.core.toolkit.StringUtils...........
注意mybatis-plus相关依赖的版本号,解决方案去
maven官方仓库
上查询版本号
错误:我的mybatis-plus-core原来是2.1.8版本,mybatis-plus-boot-starter是3.5.2版本
正确:mybatis-plus-core->3.5.2版本,mybatis-plus-boot-starter->3.5.2版本
注解问题
// MybatisPlusApplication.class: 是启动类的类名
@SpringBootTest(classes = MybatisPlusApplication.class)
@RunWith(SpringRunner.class)