关于使用ssm查询mybatis

查询条件为某一个字段,但是有多个值同时查询,sql语句要怎么写

 <select id="queryList04" resultType="map" parameterType="java.util.List">
          select CEZJRC_TXLJ,CEZJRC_XM,CEZJRC_ZY,CEZJRC_ZC from NRJRENCAI 
          where CEZJRC_BM in 
  <foreach collection="list" index="index" item="item" open="(" separator="," close=")">  
            #{item}  
       </foreach>
  </select>

第一种方式是in(v1,v2,v3)这种,看传入的值是什么,如果是集合数组mybatis里面可以遍历方式,第二种是使用instr函数,instr(value, column) > 0
使用instr注意子集问题,最后是拼接符号保证唯一性,例如instr(concat(",",value,","), concat(",",column,",")>0

  • 1. 1. FIND_IN_SET(字段,集合)
  • 2. 字段 in(value1,value2,.....)

select * from table where 字段名 in('字段值1',字段值2','字段值3','字段值4');

mybatis中的查询语句类似:


select * from table where 字段名 in



#{item}



作为list集合传入参数

select CEZJRC_TXLJ,CEZJRC_XM,CEZJRC_ZY,CEZJRC_ZC from NRJRENCAI
where CEZJRC_BM in


#{item}