如何写Mybatis XML Mapper 有两个参数(第一个是List<String>,第二个是Long)?

How to write Mybatis XML Mapper with two parameter (1st is List<String>, 2nd is Long)?

我现在的mybatismapper.xml

  <select id="batchSelect" resultMap="ResultMap">
    select id, user_id, mall_id, log, log_type
    from user_log
    where user_id in (
    <foreach collection="userList" index="index" item="item" separator=",">
      #{item,jdbcType=VARCHAR}
    </foreach>
    ) and mall_id = #{1}
  </select>

java Mapper.java

List<UserLog> batchSelect(List<String> userList, Long mallId);

当我启动spring-boot服务时,异常是:

exception: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userList' not found. Available parameters are [0, 1, param1, param2]

我怎样才能正确地写这个?

你可以使用注解@Param

List<UserLog> batchSelect(@Param("userList")List<String> userList, @Param("mailId")Long mallId);

<select id="batchSelect" resultMap="ResultMap">
    select id, user_id, mall_id, log, log_type
    from user_log
    where user_id in (
    <foreach collection="userList" index="index" item="item" separator=",">
      #{item,jdbcType=VARCHAR}
    </foreach>
    ) and mall_id = #{mailId}
  </select>

其实,mybatis-generator支持selectByExampleupdateByExample,他们都支持where in条款。

这是我最后的选择