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>
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号