在 Oracle 中,可以使用 IN 语句来实现 mapper 层的多个参数批量查询。以下是一个示例:

  1. 在 Mapper 接口中定义方法:
List<YourEntity> findByParams(@Param('param1') List<Integer> param1, @Param('param2') List<String> param2);
  1. 在 Mapper.xml 文件中实现该方法:
<select id="findByParams" resultType="YourEntity">
    SELECT * FROM your_table
    WHERE param1 IN
    <foreach collection="param1" item="item" open="(" separator="," close=")">
        #{item}
    </foreach>
    AND param2 IN
    <foreach collection="param2" item="item" open="(" separator="," close=")">
        #{item}
    </foreach>
</select>
  1. 在 Service 层中调用 Mapper 方法:
List<Integer> param1 = Arrays.asList(1, 2, 3);
List<String> param2 = Arrays.asList("A", "B", "C");
List<YourEntity> result = yourMapper.findByParams(param1, param2);

这样就可以通过多个参数进行批量查询了。

Oracle Mapper 层批量查询:使用 IN 语句实现多参数查询

原文地址: https://www.cveoy.top/t/topic/pf1v 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录