My Batis 官方文档 对 动态SQL中使用trim标签的场景及效果介绍比较少。
事实上trim标签有点类似于replace效果。
trim 属性
prefix:前缀覆盖并增加其内容
suffix:后缀覆盖并增加其内容
prefixOverrides:前缀判断的条件
suffixOverrides:后缀判断的条件
比如:
最终sql打印为:
select b.* from sys_menu b where 1 = 1 AND b.menu_name like '' WHERE
从结果可以发现:
suffix是针对符合suffixOverrides的SQL语句追加后缀suffix值。
总而言之:
And sqlxxx
最终结果是:
And sqlxxx WHERE
我不是很确认这种用法的具体场景,但是,就目前mybatis的动态sql语句来看的话,很多标签都足够用了。
insert into tracking_form
id,
admin_user_id,
admin_user_name,
user_id,
user_auth_id,
username,
requirement_num,
other_user_id,
other_user_auth_id,
otherusername,
other_requirement_num,
property_type,
reference_id,
reference_type,
reference_name,
content,
status,
is_active,
day_num,
begin_time,
end_time,
updated_time,
created_time,
receive_time,
created_by,
updated_by,
version,
#{id,jdbcType=BIGINT},
#{adminUserId,jdbcType=BIGINT},
#{adminUserName,jdbcType=VARCHAR},
#{userId,jdbcType=BIGINT},
#{userAuthId,jdbcType=BIGINT},
#{username,jdbcType=VARCHAR},
#{requirementNum,jdbcType=BIGINT},
#{otherUserId,jdbcType=BIGINT},
#{otherUserAuthId,jdbcType=BIGINT},
#{otherusername,jdbcType=VARCHAR},
#{otherRequirementNum,jdbcType=BIGINT},
#{propertyType,jdbcType=TINYINT},
#{referenceId,jdbcType=BIGINT},
#{referenceType,jdbcType=TINYINT},
#{referenceName,jdbcType=VARCHAR},
#{content,jdbcType=VARCHAR},
#{status,jdbcType=TINYINT},
#{isActive,jdbcType=TINYINT},
#{dayNum,jdbcType=BIGINT},
#{beginTime,jdbcType=TIMESTAMP},
#{endTime,jdbcType=TIMESTAMP},
#{updatedTime,jdbcType=TIMESTAMP},
#{createdTime,jdbcType=TIMESTAMP},
#{receiveTime,jdbcType=TIMESTAMP},
#{createdBy,jdbcType=VARCHAR},
#{updatedBy,jdbcType=VARCHAR},
#{version,jdbcType=INTEGER},