[Xml sql] fragment efficiencies and labels used -sql

Mybatis definition, a node is used to define reusable SQL code.
It can be included in another statement which is used to contain the node.
Further, it may be used which is $ {} placeholder parameterized (note passed in parameter here is not invoked), different attribute value varies included by way of example.

sql tag id attribute corresponding to the attribute refid include tag. The original sql sql fragments and fragments assembled into a complete label include sql statement by execution.

<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>
Published 64 original articles · won praise 33 · views 70000 +

Guess you like

Origin blog.csdn.net/shangrila_kun/article/details/104771158