gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:15:02 25 4
gpt4 key购买 nike

我当前的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com