一. 数据库的表设计中经常会有使用json存储的大字段,经常会有模糊匹配大字段的需求,在 mapper.xml 文件中如何进行模糊匹配呢。
<if test="feeType != null and feeType !=''">
and fee_extension like (CONCAT(CONCAT('%"feeType ":', #{feeType, jdbcType=VARCHAR}),'%'))
</if>
二. 若 where 条件中的字段为空,需要备用字段值进行替换。使用 otherwise
<choose>
<when test="order.isPreOrder!= null">
#{order.isPreOrder,jdbcType=INTEGER},
</when>
<otherwise>
0,
</otherwise>
</choose>
三. 如何复用一大串字段名称和对应的值?使用一个引用id——refid。
<sql id="batchInsert">
insert into tableA
<trim prefix="(" suffix=")" suffixOverrides=",">
<include refid="cn.com.mollychin.ob.TableA.Insert_Column_List"></include>
</trim>
values
<foreach collection="domainList" item="domain" separator=",">
(
<include refid="cn.com.mollychin.ob.TableA.Insert_Value_List"></include>
)
</foreach>
</sql>