Skip to content

Unable to reference collection parameter by its actual name when the first parameter is RowBounds or ResultHandler #2693

Closed
@liuzongliang0202

Description

@liuzongliang0202

org.apache.ibatis.reflection.ParamNameResolver#getNamedParams

public Object getNamedParams(Object[] args) {
    final int paramCount = names.size();
    if (args == null || paramCount == 0) {
      return null;
    } else if (!hasParamAnnotation && paramCount == 1) {
      Object value = args[names.firstKey()];
      return wrapToMapIfCollection(value, useActualParamName ? names.get(0) : null); //--------$1
    } else {
      ......
    }
 }

code line $1 'names.get(0)' should be replaced by 'names.get(names.firstKey())' . because when 'paramCount == 1' names the only key is not necessarily 0,for example:

// when useActualParamName==true
 public interface UserMapper {
    List<User> selectByStartingWithName(RowBounds rb, List<String> nameList);     
  }

<select id="selectByStartingWithName" resultMap="baseMap">
        select * from users where
                <foreach collection="nameList" separator="or" item="item" open="(" close=")">
                    `name` LIKE concat('%',#{item},'%')
                </foreach>
</select>

This test case 'names.size()==1' names contains key:1 --> value: "nameList"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions