MyBatis基本查询、条件查询、查询排序

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.inspur.analysis.tool.ontology.linkType.dao.LinkTypeMapper">

    <resultMap type="com.inspur.analysis.tool.ontology.linkType.data.LinkType" id="linkType">
        <id property="linkUri" column="LINK_URI"/>
        <result property="uriHash" column="URI_HASH"/>
        <result property="baseTypeUri" column="BASE_TYPE_URI"/>
        <result property="linkLabel" column="LINK_LABEL"/>
        <result property="isAsymmetrical" column="IS_ASYMMETRICAL"/>
        <result property="aliase" column="ALIASE"/>
        <result property="pcName" column="P_C_NAME"/>
        <result property="pcAliase" column="P_C_ALIASE"/>
        <result property="cpName" column="C_P_NAME"/>
        <result property="cpAliase" column="C_P_ALIASE"/>
        <result property="detailIconUri" column="DETAIL_ICON_URI"/>
        <result property="detailIcon" column="DETAIL_ICON"/>
        <result property="edgeIconUri" column="EDGE_ICON_URI"/>
        <result property="edgeIcon" column="EDGE_ICON"/>
        <result property="isSys" column="IS_SYS"/>
        <result property="note" column="NOTE"/>
        <result property="creatorId" column="CREATOR_ID"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="editorId" column="EDITOR_ID"/>
        <result property="editTime" column="EDIT_TIME"/>
        <result property="scn" column="SCN"/>
    </resultMap>

    <select id="existLinkTypeUri" parameterType="String"
            resultMap="linkType">
        SELECT * FROM OD_LINK_TYPE
        WHERE LINK_URI = #{linkUri}
    </select>

    <select id="isRootLinkType" parameterType="String"
            resultType="int">
        SELECT EXISTS(SELECT LINK_URI FROM OD_LINK_TYPE
                                      WHERE LINK_URI=BASE_TYPE_URI AND LINK_URI=#{linkUri})
    </select>

    <select id="deleteRootLinkType" parameterType="String">
        DELETE FROM OD_LINK_TYPE WHERE BASE_TYPE_URI=#{baseTypeUri}
    </select>

    <select id="getRootLinkTypeList"  resultMap="linkType">
        SELECT * FROM OD_LINK_TYPE
        WHERE LINK_URI =  BASE_TYPE_URI
    </select>

    <select id="getAllLinkTypeListByParent" parameterType="java.util.Map"
            resultMap="linkType">
        SELECT * FROM OD_LINK_TYPE
        <where>
            LINK_URI != BASE_TYPE_URI
            <if test="baseTypeUri != null">
              AND BASE_TYPE_URI=#{baseTypeUri}
            </if>
        </where>
        <if test="orderfield != null" >
         ORDER BY 
           <choose>    
                <when test="orderfield == 'linkUri'">    
                    LINK_URI ${orderdir} 
                </when>  
                 <when test="orderfield == 'linkLabel'">    
                    LINK_LABEL ${orderdir} 
                </when>  
                 <otherwise>
                   BASE_TYPE_URI ${orderdir}
                </otherwise> 
            </choose>    
        </if>
    </select>

    <select id="getLinkTypeListByCondition" parameterType="java.util.Map"  resultMap="linkType">
        SELECT * FROM OD_LINK_TYPE
        <where>
            LINK_URI != BASE_TYPE_URI
            <if test="linkUri != null">
               AND LINK_URI LIKE '%${linkUri}%'
            </if>
            <if test="linkLabel != null">
                AND LINK_LABEL LIKE '%${linkLabel}%'
            </if>
            <if test="baseTypeUri != null">
                AND BASE_TYPE_URI=#{baseTypeUri}
            </if>
        </where>
      <if test="orderfield != null" >
         ORDER BY 
           <choose>    
                <when test="orderfield == 'linkUri'">    
                    LINK_URI ${orderdir} 
                </when>  
                 <when test="orderfield == 'linkLabel'">    
                    LINK_LABEL ${orderdir} 
                </when>  
                 <otherwise>
                   BASE_TYPE_URI ${orderdir}
                </otherwise> 
            </choose>    
        </if>
    </select>

</mapper>

转载于:https://www.cnblogs.com/myitroad/p/7158704.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值