• mybatis中<include>标签的作用


    MyBatis中sql标签定义SQL片段,
    include标签引用,可以复用SQL片段

    sql标签中id属性对应include标签中的refid属性。通过include标签将sql片段和原sql片段进行拼接成一个完整的sql语句进行执行。

    <sql id="sqlid">
        res_type_id,res_type
    </sql>
    
    <select id="selectbyId" resultType="com.property.vo.PubResTypeVO">
        select
        <include refid="sqlid"/>
        from pub_res_type
    </select>
    • 引用同一个xml中的sql片段
    • <include refid="sqlid"/>引用公用的sql片段
    <include refid="namespace.sqlid"/>

    include标签中也可以用property标签,用以指定自定义属性。在sql标签中通过${}取出对应的属性值。

    <select id="queryPubResType" parameterType="com.property.vo.PubResTypeVO" resultMap="PubResTypeList">
        select  a.res_type_id,
        <include refid="com.common.dao.FunctionDao.SF_GET_LNG_RES_TYPE">
            <property name="AI_RES_TYPE_ID" value="a.res_type_id"/>
            <property name="lng" value="#{lngId}"/>
            <property name="female" value="''"/>
        </include> as res_type
        from    pub_res_type a
    </select>
    

    使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功。

    如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间作一个映射关系。

    resultMap:适合使用返回值是自定义实体类的情况

    resultType:适合使用返回值得数据类型是非自定义的,即jdk的提供的类型

  • 相关阅读:
    php 显示文件 与Windows文件名排序一致
    pip3 install uwsgi 报错
    centos7 安装mysql 5.7
    Win7 开始菜单搜索添加快捷方式
    centos7.7 clamav 查杀病毒
    CentOS7.x 默认php版本与php7.4共存
    centos6.5 yum安装redis
    centos6 yum安装mysql 5.6 (完整版)
    解决phpmyadmin出现: Maximum execution time of 300
    Castle Windsor 使MVC Controller能够使用依赖注入
  • 原文地址:https://www.cnblogs.com/zouhong/p/12051492.html
Copyright © 2020-2023  润新知