Mapper文件:

    <select id="selectPersonByIds" parameterType="map" resultMap="baseResultMap">
        select * from person t where t.person_id in
        <foreach collection="list" item="item" open="(" close=")"
            index="index" separator=",">
            #{item}
        </foreach>
        and t.name like #{name}
    </select>

Java文件:

@Test
    public void selectPersonByIds() {
        SqlSession session = sessionFactory.openSession();
        try {
            String statement = "com.stone.mapper.PersonMapper.selectPersonByIds";
            Map<String, Object> map = new HashMap<String, Object>();
            List<Integer> ints = new ArrayList<Integer>();
            ints.add(1);
            ints.add(8);
            ints.add(9);
            map.put("list", ints);
            map.put("name", "刘备");
            List<Person> pList = session.selectList(statement, map);
            for (Person person : pList) {
                System.out.println(person);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }

 

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-07-17
  • 2021-11-16
  • 2021-06-09
  • 2021-12-16
  • 2021-09-26
猜你喜欢
  • 2021-10-14
  • 2022-12-23
  • 2022-02-03
  • 2021-08-14
  • 2022-01-24
  • 2022-12-23
相关资源
相似解决方案