记录使用MyBatis-plus自定义SQL结尾";"引发的错误
当MP中提供的BaseMapper和Iservice中的方法不能满足我们的也无需求时,我们常常会在XXXmapper.xml文件中定制化SQL
问题展示:
这是一个普通的分页查询的动态SQL语句
<resultMap id="sysUserMap" type="com.wcj.model.system.SysUser" autoMapping="true"></resultMap>
<select id="selectPage" resultMap="sysUserMap">
select
id,
username,
password,
name,
phone,
head_url,
dept_id,
post_id,
description,
status,
create_time,
update_time,
is_deleted
from sys_user
<where>
<if test="vo.keyword != null and vo.keyword != ''">
and (username like CONCAT('%',#{vo.keyword},'%')
or name like CONCAT('%',#{vo.keyword},'%')
or phone like CONCAT('%',#{vo.keyword},'%'))
</if>
<if test="vo.createTimeBegin != null and vo.createTimeBegin != ''">
and create_time >= #{vo.createTimeBegin}
</if>
<if test="vo.createTimeEnd != null and vo.createTimeEnd != ''">
and create_time <= #{vo.createTimeBegin}
</if>
and is_deleted = 0;
</where>
order by id desc;
</select>
swagger测试时报错:
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7deaf778] was not registered
for synchronization because synchronization is not active
通过查看日志发现是***;***的问题
问题解决:把两个分号去掉就行了
总结
在xml中自定义SQL语句时,结尾尽量不要习惯性的加";"!!!