我当前的mybatis mapper.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]
我怎样才能正确写出来?
答案 0 :(得分:2)
您可以使用annonation @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>
答案 1 :(得分:0)
实际上,mybatis-generator supprot selectByExample
,updateByExample
,它们都支持where in
子句。
这是我的最终选择