mybatis xml 文件 sql include 的用法

 mybatis xml 文件中对于重复出现的sql 片段可以使用标签提取出来,在使用的地方使用标签引用即可具体用法如下:

    <sql id="Base_Column_List">
        id,name
    </sql>
    
    <select id="select">
        select
        <include refid="Base_Column_List"/>
        from t
    </select>

在sql 片段中可以使用${}传入参数,如下:

    <sql id="Base_Column_List">
        ${tableName}.id,${tableName}.name
    </sql>
    
    <select id="select">
        select
        <include refid="Base_Column_List">
            <property name="tableName" value="t"/>
        </include>
        from t
    </select>

对于多个xml文件需要同时引用一段相同的 可以在某个xml 中定义这个 sql 代码片段,在需要引用的地方使用全称引用即可,例子如下:

ShareMapper.xml

    <mapper namespace="com.lxw.ShareMapper">
        <sql id="Base_Column_List">
         id,name
        </sql>
    </mapper>

CustomMapper.xml

    <mapper namespace="com.lxw.CustomMapper">
        <select id="selectSome" >
            select
            <include refid="com.lxw.ShareMapper.Base_Column_List"/>
            from t
        </select>
    </mapper>

相关推荐

  1. mybatis xml 文件 sql include

    2023-12-23 14:54:04       39 阅读
  2. ffmpeg 从视频文件抓取图片 (帧)

    2023-12-23 14:54:04       29 阅读
  3. ffmpeg 从视频文件抓取图片 (帧)

    2023-12-23 14:54:04       28 阅读
  4. python中requirements.txt文件

    2023-12-23 14:54:04       8 阅读
  5. nc

    2023-12-23 14:54:04       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-23 14:54:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-23 14:54:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-23 14:54:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-23 14:54:04       18 阅读

热门阅读

  1. 使用xuggle_5.4 实现视频加水印

    2023-12-23 14:54:04       38 阅读
  2. mockito-study-api

    2023-12-23 14:54:04       36 阅读
  3. Mac[M1]安装mongodb

    2023-12-23 14:54:04       33 阅读
  4. 掌握 Rust 中的建造者模式

    2023-12-23 14:54:04       46 阅读
  5. Harmonyos系统使用http访问网络和应用数据管理

    2023-12-23 14:54:04       31 阅读
  6. 数据处理演进:EtLT崛起,ELT正在告别历史舞台

    2023-12-23 14:54:04       33 阅读
  7. Golang leetcode59 螺旋矩阵

    2023-12-23 14:54:04       34 阅读
  8. 基于汉宁窗FIR滤波器实现语音信号加噪去噪

    2023-12-23 14:54:04       41 阅读
  9. MySQL数据库

    2023-12-23 14:54:04       32 阅读
  10. 理解计算机中的中断与中断处理

    2023-12-23 14:54:04       45 阅读
  11. log4j rename方法

    2023-12-23 14:54:04       35 阅读
  12. python使用selenium无法获取frame完整内容的问题

    2023-12-23 14:54:04       45 阅读