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

标签 java spring-boot mybatis

我当前的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)是:

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>

关于java - 如何用两个参数(第一个是List<String>,第二个是Long)编写Mybatis XML Mapper?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49420077/

相关文章:

java - 用注解映射mybatis结果

java - hashCode 方法以防 equals 方法支持 wildchar

java - apache qpid 与 spring boot 的集成

java - Eclipse导入jar包,启动Tomcat还是找不到class

linux - Spring Boot 应用程序即服务 + VM 选项

java - Springboot 1.4/单元测试时出错(hibernate AttributeConverter 注册多次)

spring - 如何传递多个参数并使用它们?

java - 在 JButton 上绘制图像?

java - JPA多态oneToMany

java - 访问root应用程序支持macos java