springboot整合mybatis,easycode生成代碼
1.引入jar包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
2.安裝插件
在idea中使用easycode插件生成代碼,由於在線無法安裝,所以採用離線安裝。 詳細教程點擊鏈接:
easycode教程鏈接
3.整合mybatis
在resource文件目錄下新建文件,mybatis-config.xml全局配置文件,新建mapper映射文件。
mybatis-config.xml內容:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
mapper映射文件爲SQL語句
4.配置映射
在springboot全局配置文件下配置如下:
mybatis:
config-location: classpath: mybatis/mybatis-config.xml
mapper-locations: classpath: mybatis/mapper/TUserDao.xml
5.啓動測試
測試能否查詢出數據,在這裏我第一次這樣做能夠查詢來數據,後來啓動項目就無法啓動了,另外一篇博客將mapper.xml在resource目錄下如何映射的問題解釋了一下。
地址:https://blog.csdn.net/Xu_XiaoXiao_Ji/article/details/101097049