代码改变世界

mybatis用法

  youxin  阅读(16)  评论(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

 

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2018-04-14 gdb强制生成core文件
2018-04-14 c++类成员变量初始化相关问题
2016-04-14 php添加到桌面
2015-04-14 nginx php fastcgi安装
2012-04-14 hdc fibonacci number 1568
2012-04-14 多种方式求fibonacci数列
2012-04-14 杭电acm分类
点击右上角即可分享
微信分享提示