当前使用版本(必填,否则不予处理)

mybatis-plus-core-3.4.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

@TableField设置typeHandler后,导致查询条件出错

重现步骤(如果有就写完整)

SqlConditionX.java

public class SqlConditionX {
  /**
     * 数组包含
     */
    public static final String IN_ARRAY = "%s &amp;&amp; array(<foreach item=\"item\" collection=\"%s\" separator=\",\" open=\"[\" close=\"]\" index=\"\">#{item}</foreach>)";
}

MyEntity.java

    /**
     * 角色
     */
    @TableField(value = "roles", jdbcType = JdbcType.VARCHAR, typeHandler = ArrayTypeHandler.class, condition = SqlConditionX.IN_ARRAY)
    private String[] roles;

报错信息

当roles当成queryWrapper条件: new QueryWrapper(myEntity), 报以下信息:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'VARCHAR' not found. Available parameters are [ew, param1]
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
    at com.sun.proxy.$Proxy79.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
    at com.sun.proxy.$Proxy95.selectList(Unknown Source)

原因

com/baomidou/mybatis-plus-core/3.4.2/mybatis-plus-core-3.4.2-sources.jar!/com/baomidou/mybatisplus/core/metadata/TableFieldInfo.java

    /**
     * 获取 查询的 sql 片段
     *
     * @param prefix 前缀
     * @return sql 脚本片段
     */
    public String getSqlWhere(final String prefix) {
        final String newPrefix = prefix == null ? EMPTY : prefix;
        // 默认:  AND column=#{prefix + el}
        String sqlScript = " AND " + String.format(condition, column, newPrefix + el);
        // 查询的时候只判非空
        return convertIf(sqlScript, convertIfProperty(newPrefix, property), whereStrategy);
    }

这里的el在构造TableFieldInfo时,会把其他信息添加到后面:

String el = this.property;
        if (JdbcType.UNDEFINED != jdbcType) {
            this.jdbcType = jdbcType;
            el += (COMMA + "jdbcType=" + jdbcType.name());
        }

请问为什么要把这些信息加到el?

Comment From: qmdx

版本 3.4.3.2 已发布,请升级验证修复该问题,有任何问题 issue 该问题关闭!