mybatis用法
2023-04-14 14:11 youxin 阅读(23) 评论(0) 收藏 举报//引用其它mapper.xml的sql片段 <include refid="namespace.sql片段"/>
<sql>用来封装SQL语句, <include>来调用,如果用了refid="base_column_list"则:
</select> <select id="selectOne" resultMap="BaseResultMap"> select <include refid="base_col_list"/> from entity_meta where id = #{entityId} </select> <sql id="base_col_list"> id, zh_name, en_name, color, parent_entity_id, is_sys_source, recent_backup_time, is_backup </sql>
sql片段
Sql中可将重复的sql提取出来,使用时用include引用即可,最终达到sql重用的目的,如下:
//建立sql片段
<sql id="query_user_where">
<if test="id!=null and id!=''">
and id=#{id}
</if>
<if test="username!=null and username!=''">
and username like '%${username}%'
</if>
</sql>
//使用include引用sql片段
<select id="findUserList" parameterType="user" resultType="user">
select * from user
<where>
<include refid="query_user_where"/>
</where>
</select>
//引用其它mapper.xml的sql片段
<include refid="namespace.sql片段"/>
https://www.cnblogs.com/sh086/p/8375791.html

浙公网安备 33010602011771号