mybatis的xml常用标签的用法示例

01 if标签

<if test="param.phone != null and param.phone  != ''">
      AND mobile = #{param.phone}
</if>

02 foreach标签

<foreach collection="param.ids" index="index" item="item"
                                       separator="," open="(" close=")">
                #{item}
            </foreach>

03 choose when标签

s.call_num
            <choose>
                <when test="param.callNumOps ==0 ">
                    <![CDATA[ > ]]>
                </when>
                <when test="param.callNumOps ==1 ">
                    <![CDATA[ >= ]]>
                </when>
                <when test="param.callNumOps ==2 ">
                    <![CDATA[ < ]]>
                </when>
                <when test="param.callNumOps ==3 ">
                    <![CDATA[ <= ]]>
                </when>
                <when test="param.callNumOps ==4 ">
                    <![CDATA[ = ]]>
                </when>
                <otherwise>
                    <![CDATA[ = ]]>
                </otherwise>
            </choose>
            #{param.callNum}

防转义

转义的字符有 <

<![CDATA[ AND created_time <= #{param.createdTimeMax} ]]>

15 种超赞的 MyBatis 写法

posted @ 2022-06-12 17:41  进击的小蔡鸟  阅读(123)  评论(0编辑  收藏  举报