当前位置:网站首页>MySQL circulates multiple values foreach, XML writing method

MySQL circulates multiple values foreach, XML writing method

2022-06-11 05:23:00 Bug repair robot

1.dao Layer interface :

 List<User>  getUsers(@Param("statusList")List statusList,@Param("startDate")Date  startDate,@Param("endDate") Date endDate);

2.xml file :

 <select id="getUsers" resultType="User">
      SELECT
	*
    FROM
	user a
    WHERE
        <if test="statusList != null and statusList.size()>0">
            a.maintain_status in
            <foreach item="status" index="index" collection="statusList" open="("  close=")" separator=",">
                #{status}
            </foreach>
        </if>
     and DATE_FORMAT(a.update_date, '%Y-%m-%d') between date_format(#{startDate}, '%Y-%m-%d')
     and date_format(#{endDate}, '%Y-%m-%d')
    </select>

If you pass in an object

dao layer

@Param("statusList")List<user> statusList

xml The middle parameter is :#{status.status}

原网站

版权声明
本文为[Bug repair robot]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020540291386.html