Java mybatis-plus的xml文件技巧

1、in

<if test="userList != null and userList.size > 0">
    and user_id in
    <foreach collection="userList" item="item" index="index" open="(" separator="," close=")">
    #item
    </foreach>
</if>

2、移除第一个or

<trim prefixOverrides="OR">
    <if test="userId != null">
        OR (user_id = #{userId})
    </if>
    <if test="userName != null">
        OR (user_name like CONCAT("%", #{userName}, "%"))
    </if>
    <if test="carId != null">
        OR (car_id = #{carId})
    </if>
</trim>

3、include

<sql id="abc">
    <where>
        deleted = 0
    </where>
</sql>

<select id="get">
    select a, b, c from test
    <include refid="abc"></include>
</select>

 4、调用存储过程

<select id="callPro" statementType="CALLABLE">
    call sp_test(#{param1}, #{param2})
</select>

 

posted @ 2023-08-18 22:05  都是城市惹的祸  阅读(162)  评论(0)    收藏  举报