Mybatis和MybatisPlus相关

本文介绍了在XML配置文件中使用SQL查询时,如何运用LIKE操作符进行模糊搜索,IN用于列表匹配,以及使用IF和foreach进行条件判断和处理Map对象,同时涵盖了大于、小于比较和FIND_IN_SET函数的应用。
摘要由CSDN通过智能技术生成

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 &gt;=
        #{servicedate_start,jdbcType=DATE}
        and      service_date &lt;=
        #{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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值