Java老程序员紫水晶书院•文思飞扬(散文、随笔、杂文、评论、科普、日记……

Mybatis用法总结

2019-01-10  本文已影响8人  vincent201819

1.实体中忽略不映射的字段

import javax.persistence.Transient;

@Transient

2.传入字符串分割成数组

    ids:1,2,3

    <if test="@Ognl@isNotEmpty(ids)">

        AND id in

        <foreach collection="ids.split(',')" index="index" item="item" open="(" separator="," close=")">

            #{item}

        </foreach>

    </if>

3.模糊查询

    <if test="@Ognl@isNotEmpty(fullText)">

        AND (

          LOWER(t1.name) like LOWER(concat('%',#{fullText},'%'))

          OR LOWER(t1.studNo) like LOWER(concat('%',#{fullText},'%'))

        )

    </if>

4.传递多个以,隔开的参数_parameter.split(',')

<update id="updateUseTimes">

  update t_paper set useTimes = (useTimes+1) WHERE id in

  <foreach collection="_parameter.split(',')" index="index" item="item" open="(" separator="," close=")">

    #{item}

  </foreach>

</update>

上一篇 下一篇

猜你喜欢

热点阅读