Mybatis
Posted M辛三木ing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis相关的知识,希望对你有一定的参考价值。
MyBatis
1.什么是MyBatis
是一款优秀的持久层框架
数据持久化:
- 持久化就是将程序的数据在持久状态和瞬时状态转化的过程
- 内存:断电即失
- 数据库(Jdbc),io文件持久化。
持久层:
Dao层、Service层、Controller层
- 完成持久化工作的代码块
- 层界限十分明显
2.搭建环境
1.pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>MyBatis</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
2.mybatis核心配置文件
resources->mybatis核心配置文件
<?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>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/mapper/mapper.xml"/>
</mappers>
</configuration>
3.pojo编写实体类(略
需要连接数据库
4.mybatis工具类
public class myBatisUtils
private static SqlSessionFactory sqlSessionFactory;
static
try
sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("map.xml"));
catch (IOException e)
e.printStackTrace();
public static SqlSession getsqlSession()
return sqlSessionFactory.openSession();
5.Mapper接口
public interface userMapper
public List<User> getUserList();
6.接口实现(xml)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.userMapper">
<select id="getUserList" resultType="com.pojo.User">
select * from smbms_user
</select>
</mapper>
7.Junit测试
import com.pojo.User;
import com.utils.myBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import com.mapper.userMapper;
public class mapperTest
@Test
public void test()
SqlSession sqlSession = myBatisUtils.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
for (User user : mapper.getUserList())
System.out.println(user.getUserName());
sqlSession.close();
3.增删改查实现
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.userMapper">
<delete id="deleteById" parameterType="int">
delete
from smbms_user
where id = #id;
</delete>
<select id="getUserList" resultType="com.pojo.User">
select * from smbms_user
</select>
<select id="selectById" resultType="com.pojo.User">
select * from smbms_user where id = #id
</select>
<update id="updatePwdById" parameterType="com.pojo.User">
update smbms_user set userPassword = #userPassword where id = #id
</update>
</mapper>
3.1 Map传参
java接口
public int updatePwdById(Map<String,Object> map);
mapper定义sql语句,传参类型为map
<update id="updatePwdById" parameterType="map">
update smbms_user set userPassword = #pwd where id = #id
</update>
测试类
@Test
public void test2()
SqlSession sqlSession = myBatisUtils.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
Map<String,Object> integerStringHashMap = new HashMap<>();
integerStringHashMap.put("id",6);
integerStringHashMap.put("pwd","123456");
mapper.updatePwdById(integerStringHashMap);
sqlSession.commit();
sqlSession.close();
优势:在实体类属性过多的情况下,选择性追踪主要参数并以map存储,且可以多次传参
4.解决属性名与字段名不一致的问题
<resultMap id="Map" type="User">
<result column="userName" property="userCode"/>
</resultMap>
<select id="getUserListLike" resultMap="Map">
select *
from smbms_user where userName
like #value;
</select>
public void test4()
SqlSession sqlSession = myBatisUtils.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
List<User> list = mapper.getUserListLike("李%");
for (User user : list)
System.out.println(user);
6.日志
如果一个数据库操作出现异常,日志是最好的排错助手,setting中导入
LOG4J STDOUT_LOGGING
SLF4J在springboot有用
STDOUT_LOGGING:
-
name :logImpl
-
value:STDOUT_LOGGING
在mybatis核心配置文件中配置日志。
<settings>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
LOG4J
-
理解:Log4j是Apache的一个开源项目,可以控制日志信息输送的目的地是控制台、文件、GUI组件,可以控制每一条日志的输出格式
-
操作:
-
建立log4j.properties
-
配置
<setting name="logImpl" value="log4j"/>
log4j.rootLogger=DEBUG,console,file #控制台输出的相关设置 log4j.appender.console = org.apache.log4j.ConsoleAppender log4j.appender.console.Target = System.out log4j.appender.console.Threshold=DEBUG log4j.appender.console.layout = org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=[%c]-%m%n #文件输出的相关设置 log4j.appender.file = org.apache.log4j.RollingFileAppender log4j.appender.file.File=./log/kuang.log log4j.appender.file.MaxFileSize=10mb log4j.appender.file.Threshold=DEBUG log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=[%p][%dyy-MM-dd][%c]%m%n #日志输出级别 log4j.logger.org.mybatis=DEBUG log4j.logger.java.sql=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.ResultSet=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
-
配置log4j为日志的实现
-
简单使用
-
在Log4j的类中导入包import org.apache.log4j.Logger;
-
日志对象,参数为当前类的class
@Test public void test() Logger logger = Logger.getLogger(Log4jTest.class); logger.info("info:进入了log4j"); logger.debug("debug:进入了log4j"); logger.error("error:进入了log4j");
-
使用例子
static Logger logger = Logger.getLogger(mapperTest.class); @Test public void test() SqlSession sqlSession = myBatisUtils.getsqlSession(); userMapper mapper = sqlSession.getMapper(userMapper.class); for (User user : mapper.getUserList()) System.out.println(user.getUserName()); logger.info("测试点"); sqlSession.close();
-
点开日志
[DEBUG][21-12-02][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@6cd28fa7] [DEBUG][21-12-02][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@6cd28fa7] [DEBUG][21-12-02][org.apache.ibatis.datasource.pooled.PooledDataSource]Returned connection 1825738663 to pool. [DEBUG][21-12-02][org.apache.ibatis.logging.LogFactory]Logging initialized using \'class org.apache.ibatis.logging.log4j.Log4jImpl\' adapter. [DEBUG][21-12-02][org.apache.ibatis.logging.LogFactory]Logging initialized using \'class org.apache.ibatis.logging.log4j.Log4jImpl\' adapter. [DEBUG][21-12-02][org.apache.ibatis.io.VFS]Class not found: org.jboss.vfs.VFS [DEBUG][21-12-02][org.apache.ibatis.io.JBoss6VFS]JBoss 6 VFS API is not available in this environment. [DEBUG][21-12-02][org.apache.ibatis.io.VFS]Class not found: org.jboss.vfs.VirtualFile [DEBUG][21-12-02][org.apache.ibatis.io.VFS]VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment. [DEBUG][21-12-02][org.apache.ibatis.io.VFS]Using VFS adapter org.apache.ibatis.io.DefaultVFS [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Find JAR URL: file:/C:/Users/29522/Desktop/%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%992.0/MyBatis/target/classes/com/pojo [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Not a JAR: file:/C:/Users/29522/Desktop/%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%992.0/MyBatis/target/classes/com/pojo [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Reader entry: User.class [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Listing file:/C:/Users/29522/Desktop/%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%992.0/MyBatis/target/classes/com/pojo [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Find JAR URL: file:/C:/Users/29522/Desktop/%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%992.0/MyBatis/target/classes/com/pojo/User.class [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Not a JAR: file:/C:/Users/29522/Desktop/%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%992.0/MyBatis/target/classes/com/pojo/User.class [DEBUG][21-12-02][org.apache.ibatis.io.DefaultVFS]Reader entry: ����
-
-
7.分页
减少数据的处理量
Limit分页
select * from table limit 0,2;
解释:从第1个开始往后查2位
select * from table limit 2;
解释:从第1个开始往后查到第3位
7.1使用Mybatis实现分页
-
接口
// 分页查询 public List<User> getUserByLimit(Map<String,Integer> map);
-
mapper.xml
<select id="getUserByLimit" parameterType="map" resultType="User"> select * from smbms_user limit #startIndex,#pageSize </select>
-
测试
@Test
public void test5()
SqlSession sqlSession = myBatisUtils.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
HashMap<String, Integer> map = new HashMap<>();
map.put("startIndex",0);
map.put("pageSize",2);
List<User> userByLimit = mapper.getUserByLimit(map);
for (User user : userByLimit)
System.out.println(user);
sqlSession.close();
7.2RowBounds分页
我不会
7.3分页插件
PageHelper:
8.注解开发
面向接口编程,解耦
(注解一时爽,维护火葬场)
注解的增删改查CRUD
-
配置mapper,将接口注册绑定到核心配置文件
<mapper class="com.mapper.userMapper"/>
-
设置环境配置,自动提交事务
public static SqlSession getsqlSession() return sqlSessionFactory.openSession(true);
-
注解带参
@Update("update smbms.smbms_user set userPassword = #pwd where id = #id") public int updatePwdByIdInn(@Param("pwd")String pwd,@Param("id") int id);
其实@Param("key")
- 基本类型的参数或者String类型,需要补充@Param的参数
- 引用类型不需要加
- 如果只有一个基本类型,可以忽略
Lombok
从maven中导包,通过注解可以自动封装实体类,但不推荐使用
-
@Data
-
@AllArgsConstructor(构造满参函数)
-
@NoArgsConstructor(构造无参函数)
-
@toString
-
@Getter & Setter
9.多对一处理
学生对老师
1.测试环境搭建
-
实体类Teacher,Student
-
建立Mapper接口
-
建立Mapper.xml
-
核心配置文件中绑定注册Mapper接口或文件
-
测试,成功进入下一步
2.按照查询嵌套处理
<mapper namespace="com.mapper.StudentMapper">
<select id="getStudent" resultMap="StudentTeacher">
select * from student
</select>
<resultMap id="StudentTeacher" type="com.pojo.Student">
<result property="id" column="id"/>
<result property="name" column="name"/>
<association property="teacher" column="tid" javaType="com.pojo.Teacher" select="getTeacher"/>
</resultMap>
<select id="getTeacher" resultType="com.pojo.Teacher">
select * from teacher where id = #id
</select>
</mapper>
3.按照结果嵌套查询
<mapper namespace="com.mapper.StudentMapper">
<select id="getStudent" resultMap="StudentTeacher">
select s.id sid,s.name sname,t.name tname
from student s,teacher t
where s.tid = t.id
</select>
<resultMap id="StudentTeacher" type="com.pojo.Student">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<association property="teacher" javaType="com.pojo.Teacher">
<result property="name" column="tname"/>
</association>
</resultMap>
</mapper>
mysql多对一查询方式
- 子查询
- 联表查询
10.一对多处理
老师对学生
1.按结果嵌套查询(推荐使用,原生sql)
public interface teacherMapper
public List<Teacher> getTeacher();
public List<Teacher> getTeacherById(@Param("tid")int id);
<mapper namespace="com.mapper.teacherMapper">
<select id="getTeacher" resultType="com.pojo.Teacher">
select * from teacher
</select>
<select id="getTeacherById" resultMap="TeacherStudent">
select s.id sid,s.name sname,t.name tname,t.id tid from student s,teacher t
where s.tid = t.id and t.id = 1;
</select>
<resultMap id="TeacherStudent" type="com.pojo.Teacher">
<result property="name" column="tname"/>
<result property="id" column="tid"/>
<collection property="getStudents" ofType="com.pojo.Student">
<result property="id" column="sid"/>
<result property="name" column="sname"/>
<result property="tid" column="tid"/>
</collection>
</resultMap>
</mapper>
2.按子查询方式查询
想查询老师再查询学生
<mapper namespace="com.mapper.teacherMapper">
<!-- 需要区别的是
ofType 针对于实体对象
javaType 对应集合对象-->
<!-- private List<Student> getStudents;-->
<select id="getStudentByTid" resultMap="TeacherStudent2">
select * from teacher where id = #tid
</select>
<resultMap id="TeacherStudent2" type="com.pojo.Teacher">
<collection property="getStudents" javaType="ArrayList" ofType="com.pojo.Student" select="getStudentByTeacherId" column="id"/>
</resultMap>
<select id="getStudentByTeacherId" resultType="com.pojo.Student">
select * from student where tid = #tid
</select>
</mapper>
3.总结
- 关联association 多对一
- 集合collection 一对多
- javaType指定实体类中的属性类型
- ofType指定映射到List或集合中的pojo类型,泛型中的约束类型
11.动态sql
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.blogMapper">
<insert id="addBlok" parameterType="com.pojo.Blog" >
insert into blog (id,title,author,create_time,views)
values (#id,#title,#author,#createTime,#views);
</insert>
<select id="quaryBlogIF" parameterType="map" resultType="com.pojo.Blog">
select * from blog
where 1=1
<if test="title != null">
and title = #title
</if>
<if test="author != null">
and author = #author
</if>
</select>
</mapper>
public interface blogMapper
// 插入数据
int addBlok(Blog blog);
// 查询博客
List<Blog> quaryBlogIF(Map map);
@Test
public void testBlog()
SqlSession sqlSession = myBatisUtil.getSqlSession();
blogMapper mapper = sqlSession.getMapper(blogMapper.class);
Blog blog = new Blog();
blog.setId(IDutils.getID());
blog.setAuthor("卢本伟");
blog.setTitle("牛逼");
blog.setCreateTime(new Date());
blog.setViews(3);
mapper.addBlok(blog);
sqlSession.close();
@Test
public void testBlogIF()
SqlSession sqlSession = myBatisUtil.getSqlSession();
blogMapper mapper = sqlSession.getMapper(blogMapper.class);
HashMap hashMap = new HashMap();
hashMap.put("title","牛逼");
for (Blog blog : mapper.quaryBlogIF(hashMap))
System.out.println(blog);
sqlSession.close();
1.if
将上述实例
2.choose(when,otherwise)
3.trim(where,set)
4.sql片段(sql,include)
建议包含if片段
5.foreach
通用初始化
resources 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>
<properties resource="pd.properties"/>
<settings>
<setting name="logImpl" value="log4j"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="$driver"/>
<property name="url" value="$url"/>
<property name="username" value="$username"/>
<property name="password" value="$password"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="Mapper路径"/>
</mappers>
</configuration>
sqlbase.properties
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT
username = root
password = 123456
log4j.properties
log4j.rootLogger=DEBUG,console,file
#??????????
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%c]-%m%n
#?????????
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./log/kuang.log
log4j.appender.file.MaxFileSize=10mb
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%dyy-MM-dd][%c]%m%n
#??????
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
mapper镜像.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="接口路径">
</mapper>
mapper接口.java
pojo/实体类
Utils
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
private static SqlSessionFactory sqlSessionFactory;
static
String src = "map.xml";
InputStream resourceAsStream = null;
try
resourceAsStream = Resources.getResourceAsStream(src);
catch (IOException e)
e.printStackTrace();
sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
public static SqlSession getSqlSession()
return sqlSessionFactory.openSession(true);
pom.xml
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-install-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.10.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.13</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/map</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
以上是关于Mybatis的主要内容,如果未能解决你的问题,请参考以下文章
SSM-MyBatis-05:Mybatis中别名,sql片段和模糊查询加getMapper
MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段