Springboot整合Mybatis及注意事项
2020-07-21 04:14
1561 查看
Mybatis文件的生成参考上篇mybatis-generator的介绍https://blog.csdn.net/d20062056/article/details/106750447
一、引入依赖
[code] <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
二、application.yaml文件配置数据库连接信息
[code]spring: datasource: url: jdbc:mysql://localhost:3306/java2020?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver mybatis: mapper-locations: classpath:/mapper/*.xml
注意事项:
1、driver如果用com.mysql.jdbc.Driver启动时会有如下提醒:
2、未配置serverTimeZone访问时会报错(可正常启动):
3、小插曲:mybatis:mapper-locations这里漏掉“s”,导致访问时报错:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),排查好久才发现。
三、SpringBoot的启动类加上@MapperScan("com.everest.springboot.mapper")
如果忘记加会启动失败,有如下提醒:
四、输出执行的SQL(方便调试)
[code]mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
相关文章推荐
- Spring boot 集成mybatis通用mapper配置步骤及注意事项
- Spring Boot整合Mybais与事务管理的注意事项
- springboot整合mybatis打印sql注意
- Spring整合Mybatis的注意事项
- Spring+SpringMvc+Mybatis整合注意事项
- mybaties+maven+springboot整合将查询结果映射到实体Bean时的注意事项
- Spring Boot整合邮件发送与注意事项
- spring boot + dubbo整合注意事项
- SpringBoot-Mybatis的整合之注意的地方
- idea搭建一个springboot+mybatis项目注意事项
- springboot与mybatis的整合
- spring boot 2.x 系列 —— spring boot 整合 druid+mybatis
- springboot整合mybatis增删改查(三):mybatis逆向工程
- springboot整合mybatis中的坑
- springboot多模块化整合mybatis,出现mapper自动注入失败问题
- springboot整合tk.mybatis
- Spring boot整合mybatis
- Spring boot+mybatis整合
- Spring Boot学习之旅:(十六)整合mybatis及日志
- 利用springboot,mybatis和luncene整合创建博客系统(只给出全数据库搜索并显示在搜索页面)