1. @Select 注解中使用like
@Select("SELECT m.* FROM table m
WHERE m.col LIKE concat('%',#{wrong},'%') ")
List<test> list(@Param("wrong") String wrong);
2.xml中写sql使用like
<select id="listTest1"
parameterType="com......"
resultMap="BaseResultMap">
select t.col
from table t
where t.del_flag = 0
<if test="search != null">
and (t.dep_name like "%"#{search}"%" or t.name like "%"#{search}"%" )
</if>
</select>
3. xml中使用 in , <foreach>映射到Map对象集合中
<select id="getTestMapList" parameterType="list" resultType="java.util.Map">
SELECT t.col1,t.col2
FROM table t
WHERE t.id in
<foreach item="item" collection="list" open="(" separator="," close=")" index="index">
#{item}
</foreach>
</select>
4.xml中使用大于,小于
<select id="getTest1"
parameterType="com....."
resultType="java.lang.Integer">
select id
from test
where service_date >=
#{servicedate_start,jdbcType=DATE}
and service_date <=
#{servicedate_end,jdbcType=DATE}
</select>
5. FIND_IN_SET函数,in字符串(格式如:"1,3,6")
<select id="listTest"
parameterType="java.lang.String"
resultType="com.....">
SELECT *
FROM table
where FIND_IN_SET(id, #{idStr})
</select>