报错截图:

翻译:
Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
已由XML或SqlProvider加载,忽略SQL的注入。
环境版本:
- SpringBoot:v2.1.1.RELEASE
- MybatisPlus:3.0.6
我的代码:
dao层接口
@Repository("integralDao")
public interface IntegralDao extends BaseMapper<IntegralEntity> {
Integer selectCount();
}
Mapper
<?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.tfjybj.typing.provider.dao.IntegralDao">
<select id="selectCount" resultType="int">
SELECT
count(*)
FROM
`ty_integral`
WHERE
is_delete =0
</select>
</mapper>
解决办法:
给Dao层接口换个其他的名字就好了。
原因:
因为使用的是MybatisPlus,并且在Dao层继承了MybatisPlus的BaseMapper,使得他具有了一些默认方法,然后你写的dao层接口的名字,正好和mybatisplus自己封装的sql的名字重复了,所以才会出现这种问题。
下图是笔者截取的 com.baomidou.mybatisplus.core.mapper下的代码,图中的确红色框框的方法名字和我写的方法名字重复了,所以给出了红色提示。

感谢您的阅读,因为笔者能力有限,如有错误,还望各位大佬们,指点迷津
本文介绍了一个关于MybatisPlus中SQL注入警告的问题及其解决办法。问题出现在使用自定义SQL选择计数时,由于方法名与MybatisPlus默认方法冲突导致。更换DAO接口名称即可解决。
1828





