springboot集成Mybatis的详细教程
springboot集成Mybatis
第一步:
【springboot集成Mybatis的详细教程】添加Mybatis依赖
org.mybatis.spring.boot mybatis-spring-boot-starter2.0.0
第二步:
添加mysql驱动
之所以没有版本号,因为它继承的是父工程的。当然你也可以自己指定一个版本号
mysql mysql-connector-java

文章图片
使用Mybatis提供的逆向工程 生成实体bean,映射文件,DAO接口
第一步:
在项目根目录创建 GeneratorMapper.xml 文件,配置如下:

文章图片
第二步
在pom.xml中配置如下:
org.mybatis.generator mybatis-generator-maven-plugin1.3.7 mysql mysql-connector-java8.0.15 GeneratorMapper.xml true true
第三步
双击如下执行时,

文章图片
这里有一个坑,我的在这里报错了,报错信息如下:
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project sprint_boot_01: Communications link failure

文章图片
百分之99是驱动和配置数据库信息中的connectionURL配置错了,我的解决方案:
driverClass="com.mysql.cj.jdbc.Driver"connectionURL="jdbc:mysql://127.0.0.1:3306/java_pro?serverTimezone=Asia/Shanghai& useUnicode=true& characterEncoding=utf8& useSSL=false"
然后在双击执行,成功:

文章图片
生成的目录如下:

文章图片
到此这篇关于springboot集成Mybatis的详细教程的文章就介绍到这了,更多相关springboot集成Mybatis内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- Activiti(一)SpringBoot2集成Activiti6
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- mybatisplus如何在xml的连表查询中使用queryWrapper
- mybatisplus|mybatisplus where QueryWrapper加括号嵌套查询方式
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- 私有化轻量级持续集成部署方案--03-部署web服务(下)
- Spring集成|Spring集成 Mina