mybatis遇到问题

mybatis自动生成的mapper.xml出错,错误信息如下

### Error querying database.  Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'like "%"?"%"',expect QUES, actual QUES % : select count(*) from t_miner_recycle_whitelist
     WHERE  user_id like "%"?"%"
### The error may exist in file [G:\codes\java\bitmain\base-common-service-web\target\classes\mapper\MinerRecycleWhitelistMapper.xml]
### The error may involve com.bitmain.shop.base.mapper.MinerRecycleWhitelistMapper.getCountByParam
### The error occurred while executing a query
### SQL: select count(*) from t_miner_recycle_whitelist      WHERE  user_id like "%"?"%"
### Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'like "%"?"%"',expect QUES, actual QUES % : select count(*) from t_miner_recycle_whitelist
     WHERE  user_id like "%"?"%"
; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; sql injection violation, syntax error: syntax error, error in :'like "%"?"%"',expect QUES, actual QUES % : select count(*) from t_miner_recycle_whitelist
     WHERE  user_id like "%"?"%"; nested exception is java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'like "%"?"%"',expect QUES, actual QUES % : select count(*) from t_miner_recycle_whitelist
     WHERE  user_id like "%"?"%"

查看xml文件

<sql id="join_list_where">
    <if test="userId != null and userId != '' ">
      AND user_id like "%"#{userId}"%"
    </if>
    <if test="userType !=null and userType!= '' ">
      AND user_type like "%"#{userType}"%"
    </if>
    <if test="creator !=null and creator!= '' ">
      AND creator like "%"#{creator}"%"
    </if>
</sql>

改为${}拼接的方式则可以:

<sql id="join_list_where">
    <if test="userId != null and userId != '' ">
      AND user_id like '%'${userId}%'
    </if>
    <if test="userType !=null and userType!= '' ">
      AND user_type like '%'#{userType}'%'
    </if>
    <if test="creator !=null and creator!= '' ">
      AND creator like '%'#{creator}'%'
    </if>
</sql>

这种拼接方式为什么会有问题?

据说是druid连接池的bug,不知道是否准确,暂做记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值