欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mybatis.xml中有哪些sql編寫規(guī)范-創(chuàng)新互聯(lián)

本篇文章為大家展示了mybatis.xml中有哪些sql編寫規(guī)范,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

十余年專注建站、設(shè)計、互聯(lián)網(wǎng)產(chǎn)品按需制作網(wǎng)站服務(wù),業(yè)務(wù)涵蓋高端網(wǎng)站設(shè)計、商城開發(fā)、微信小程序、軟件系統(tǒng)開發(fā)、手機APP定制開發(fā)等。憑借多年豐富的經(jīng)驗,我們會仔細了解每個客戶的需求而做出多方面的分析、設(shè)計、整合,為客戶設(shè)計出具風(fēng)格及創(chuàng)意性的商業(yè)解決方案,創(chuàng)新互聯(lián)公司更提供一系列網(wǎng)站制作和網(wǎng)站推廣的服務(wù),以推動各中小企業(yè)全面信息數(shù)字化,并利用創(chuàng)新技術(shù)幫助各行業(yè)提升企業(yè)形象和運營效率。

一、越少的代碼,越強悍的功能,xml里面應(yīng)該6個sql語句就夠用了,修改,維護成本很低,見下表 下載


英文名方法名稱核心點建議
insert1.新增數(shù)據(jù)如果是自增主鍵,應(yīng)該返回主鍵ID
deleteById2. 根據(jù)主鍵ID刪除數(shù)據(jù)sql默認加limit 1,防止多刪數(shù)據(jù)此方法不建議有,建議邏輯刪除
updateById3. 根據(jù)主鍵ID修改數(shù)據(jù)sql默認加limit 1,防止多修改數(shù)據(jù)
selectById4. 根據(jù)主鍵查詢數(shù)據(jù)查詢一條數(shù)據(jù)
selectByIdForUpdate5. 根據(jù)主鍵加鎖查詢數(shù)據(jù)加鎖查詢一條數(shù)據(jù),事務(wù)處理用
queryListByParam6. 根據(jù)輸入條件查詢數(shù)據(jù)列表和7配合使用
queryCountByParam7. 根據(jù)輸入條件查詢總數(shù)和6配合使用


二、公共的查詢條件和字段列表等抽出公共sql段,方便使用


英文名方法名稱核心點建議
_field_list1.字段列表修改方便,方便字段排序
_value_list2. 字段值列表修改方便,方便字段值排序
_common_where3. 通用查詢條件每個字段的等值判斷
_regin_where4. 通用范圍區(qū)間條件字段的時間區(qū)間,字段的金額區(qū)間等的判斷
_contain_where5. 包含字段值范圍條件字段的常量值包含判斷,in ,not in
_common_sorts6. 通用排序條件order by


三、一個mybatis.xml例子  下載


Sql代碼

<?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="Assets">  
  
  
    <!-- 設(shè)置1分鐘緩存,緩存大小1024,采用最近最少使用算法 -->  
    <cache readOnly="true" flushInterval="60000" size="10" eviction="LRU" />  
  
    <resultMap type="Assets" id="AssetsResultMap">  
        <id property="id" column="id" />  
        <result property="userId" column="user_id" />  
        <result property="amount" column="amount" />  
        <result property="earning" column="earning" />  
        <result property="type" column="type" />  
        <result property="status" column="status" />  
        <result property="productId" column="product_id" />  
        <result property="productName" column="product_name" />  
        <result property="cardNo" column="card_no" />  
        <result property="bankCode" column="bank_code" />  
        <result property="orderId" column="order_id" />  
        <result property="effectiveDate" column="effective_date" />  
        <result property="redeemType" column="redeem_type"/>  
        <result property="initAmount" column="init_amount"/>  
        <result property="initEarning" column="init_earning"/>  
        <result property="redeemingAmount" column="redeeming_amount"/>  
        <result property="redeemingEarning" column="redeeming_earning"/>  
        <result property="redeemedAmount" column="redeemed_amount"/>  
        <result property="redeemedEarning" column="redeemed_earning"/>  
        <result property="punishAmount" column="punish_amount"/>  
        <result property="latestRedeemTime" column="latest_redeem_time"/>  
        <result property="maturityDate" column="maturity_date"/>  
        <result property="createTime" column="create_time" />  
        <result property="modifyTime" column="modify_time" />  
        <result property="remark" column="remark" />  
    </resultMap>  
  
    <!-- 字段列表 -->  
    <sql id="_field_list">  
        id,   
        user_id,   
        amount,   
        earning,   
        type,   
        status,   
        product_id,   
        product_name,  
        card_no,   
        bank_code,   
        order_id,   
        effective_date,   
        redeem_type,   
        init_amount,   
        init_earning,   
        redeeming_amount,  
        redeeming_earning,  
        redeemed_amount,   
        redeemed_earning,   
        punish_amount,  
        latest_redeem_time,   
        maturity_date,  
        create_time,   
        modify_time,  
        remark  
    </sql>  
  
    <!-- 字段值列表 -->  
    <sql id="_value_list">  
        #{id},   
        #{userId},  
        #{amount},   
        #{earning},   
        #{type},   
        #{status},   
        #{productId},   
        #{productName},   
        #{cardNo},   
        #{bankCode},   
        #{orderId},   
        #{effectiveDate},   
        #{redeemType},   
        #{initAmount},   
        #{initEarning},   
        #{redeemingAmount},  
        #{redeemingEarning},  
        #{redeemedAmount},   
        #{redeemedEarning},   
        #{punishAmount},  
        #{latestRedeemTime},   
        #{maturityDate},  
        #{createTime},  
        #{modifyTime},   
        #{remark}  
    </sql>  
  
    <!-- 通用查詢條件  不支持ID查詢條件,ID的直接通過ID即可以查 -->  
    <sql id="_common_where">  
        <if test="id != null"> AND id = #{id}</if>  
        <if test="userId != null"> AND user_id = #{userId}</if>  
        <if test="amount != null"> AND amount = #{amount}</if>  
        <if test="earning != null"> AND earning = #{earning}</if>  
        <if test="type != null"> AND type = #{type}</if>  
        <if test="status != null"> AND status = #{status}</if>  
        <if test="productId != null"> AND product_id = #{productId}</if>  
        <if test="productName != null"> AND product_name = #{productName}</if>  
        <if test="cardNo != null"> AND card_no = #{cardNo}</if>  
        <if test="bankCode != null"> AND bank_code = #{bankCode}</if>  
        <if test="orderId != null"> AND order_id = #{orderId}</if>  
        <if test="effectiveDate != null"> AND effective_date = #{effectiveDate}</if>  
        <if test="redeemType != null"> AND redeem_type = #{redeemType}</if>  
        <if test="initAmount != null"> AND init_amount = #{initAmount}</if>  
        <if test="initEarning != null"> AND init_earning = #{initEarning}</if>  
        <if test="redeemingAmount != null"> AND redeeming_amount = #{redeemingAmount}</if>  
        <if test="redeemingEarning != null"> AND redeeming_earning = #{redeemingEarning}</if>  
        <if test="redeemedAmount != null"> AND redeemed_amount = #{redeemedAmount}</if>  
        <if test="redeemedEarning != null"> AND redeemed_earning = #{redeemedEarning}</if>  
        <if test="punishAmount != null"> AND punish_amount = #{punishAmount}</if>  
        <if test="latestRedeemTime != null">  
            <![CDATA[  
                AND latest_redeem_time = #{latestRedeemTime, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
        <if test="maturityDate != null">  
            <![CDATA[  
                AND maturity_date = #{maturityDate, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
        <if test="createTime != null">  
            <![CDATA[  
                AND create_time = #{createTime, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
        <if test="modifyTime != null">  
            <![CDATA[  
                AND modify_time = #{modifyTime, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
        <if test="remark != null"> AND remark = #{remark}</if>  
    </sql>  
      
      
    <!-- 通用范圍區(qū)間查詢 -->  
    <sql id="_regin_where">  
        <if test="egtCreateTime != null">  
            <![CDATA[  
                AND create_time >= #{egtCreateTime, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
        <if test="ltCreateTime != null">  
            <![CDATA[  
                AND create_time < #{ltCreateTime, jdbcType=TIMESTAMP}   
            ]]>  
        </if>  
    </sql>  
      
      
    <!-- 通用排序處理 -->  
    <sql id="_common_sorts">  
        <if test="sorts != null">  
            ORDER BY  
            <foreach collection="sorts" item="item" separator=",">  
                ${item.column.columnName} ${item.sortMode.mode}  
            </foreach>  
        </if>  
    </sql>  
      
      
    <!-- in 和 not in的通用查詢where -->  
    <sql id="_contain_where">  
        <if test="containStatusSet!=null">  
            AND status IN  
            <foreach item="item" index="i" collection="containStatusSet" separator="," open="(" close=")" >    
                #{item}    
            </foreach>  
        </if>  
          
    </sql>  
      
      
    <!-- 插入操作 -->  
    <insert id="insert" parameterType="Assets">  
        INSERT INTO assets (  
            <include refid="_field_list"/>)  
        VALUES (  
            <include refid="_value_list"/>)  
    </insert>  
  
  
    <!-- 根據(jù)ID主鍵進行刪除,注意limit 1 -->  
    <delete id="deleteById"  parameterType="java.lang.String" >  
        delete from assets where id = #{id} limit 1  
    </delete>   
  
  
    <!-- 根據(jù)主鍵ID進行更新,注意limit 1 -->  
    <update id="updateById" parameterType="Assets">  
        UPDATE assets  
        <set>  
            <if test="userId != null">  
                user_id = #{userId},  
            </if>  
            <if test="amount != null">  
                amount = #{amount},  
            </if>  
            <if test="earning != null">  
                earning = #{earning},  
            </if>  
            <if test="type != null">  
                type = #{type},  
            </if>  
            <if test="status != null">  
                status = #{status},  
            </if>  
            <if test="productName != null">  
                product_name = #{productName},  
            </if>  
            <if test="productId != null">  
                product_id = #{productId},  
            </if>  
            <if test="cardNo != null">  
                card_no = #{cardNo},  
            </if>  
            <if test="bankCode != null">  
                bank_code = #{bankCode},  
            </if>  
            <if test="orderId != null">  
                order_id = #{orderId},  
            </if>  
            <if test="effectiveDate != null">  
                effective_date = #{effectiveDate},  
            </if>  
            <if test="redeemType != null">  
                redeem_type = #{redeemType},  
            </if>  
            <if test="initAmount != null">  
                init_amount = #{initAmount},  
            </if>  
            <if test="initEarning != null">  
                init_earning = #{initEarning},  
            </if>  
            <if test="redeemingAmount != null">  
                redeeming_amount = #{redeemingAmount},  
            </if>  
            <if test="redeemingEarning != null">  
                redeeming_earning = #{redeemingEarning},  
            </if>  
            <if test="redeemedAmount != null">  
                redeemed_amount = #{redeemedAmount},  
            </if>  
            <if test="redeemedEarning != null">  
                redeemed_earning = #{redeemedEarning},  
            </if>  
            <if test="punishAmount != null">  
                punish_amount = #{punishAmount},  
            </if>  
            <if test="latestRedeemTime != null">  
                latest_redeem_time = #{latestRedeemTime},  
            </if>  
            <if test="maturityDate != null">  
                maturity_date = #{maturityDate},  
            </if>  
            <if test="modifyTime != null">  
                modify_time = #{modifyTime},  
            </if>  
            <if test="remark != null">  
                remark = #{remark},  
            </if>  
        </set>  
  
        <where>  
            id = #{id} limit 1  
        </where>  
    </update>  
  
  
    <!-- 根據(jù)ID進行查詢 -->  
    <select id="selectById" resultMap="AssetsResultMap">  
        select * from assets where id = #{id}  
    </select>  
      
      
    <!-- 根據(jù)ID進行加行鎖查詢 -->  
    <select id="selectByIdForUpdate" resultMap="AssetsResultMap">  
        select * from assets where id = #{id} for update  
    </select>  
  
      
    <!-- 根據(jù)查詢條件查詢數(shù)據(jù)和queryCountByParam方法配對使用 -->  
    <select id="queryListByParam" parameterType="map" resultMap="AssetsResultMap">  
        SELECT   
            <include refid="_field_list"/>  
        FROM   
            assets  
        <where>  
            1 = 1  
            <include refid="_common_where"/>  
            <include refid="_regin_where"/>  
            <include refid="_contain_where"/>  
        </where>  
          
        <include refid="_common_sorts"/>  
          
        <if test="offset != null and rows != null">  
            limit #{offset}, #{rows}  
        </if>  
    </select>  
      
      
    <!-- 根據(jù)查詢條件查詢總數(shù)和queryListByParam方法配對使用 -->  
    <select id="queryCountByParam" parameterType="map" resultType="java.lang.Integer">  
        SELECT count(1) FROM assets  
        <where>  
            1 = 1  
            <include refid="_common_where"/>  
            <include refid="_regin_where"/>  
            <include refid="_contain_where"/>  
        </where>  
    </select>  
      
</mapper>

上述內(nèi)容就是mybatis.xml中有哪些sql編寫規(guī)范,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

標(biāo)題名稱:mybatis.xml中有哪些sql編寫規(guī)范-創(chuàng)新互聯(lián)
文章源于:http://chinadenli.net/article30/ehcpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、自適應(yīng)網(wǎng)站用戶體驗、網(wǎng)站制作電子商務(wù)、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
亚洲夫妻性生活免费视频| 欧美日韩国产亚洲三级理论片| 98精品永久免费视频| 老富婆找帅哥按摩抠逼视频| 亚洲伦理中文字幕在线观看| 国产原创激情一区二区三区| 日韩精品一区二区三区四区| 激情亚洲一区国产精品久久| 色综合久久超碰色婷婷| 91精品国自产拍老熟女露脸| 中文字幕人妻av不卡| 特黄大片性高水多欧美一级| 国产性色精品福利在线观看| 国产香蕉国产精品偷在线观看| 欧美精品久久一二三区| 国产丝袜女优一区二区三区| 国产一区二区在线免费| 正在播放玩弄漂亮少妇高潮| 日韩精品一区二区不卡| 午夜精品福利视频观看| 欧美日韩国产福利在线观看| 亚洲男人天堂成人在线视频| 日韩精品一区二区三区射精| 亚洲精品中文字幕在线视频| 日韩精品小视频在线观看| 老司机精品福利视频在线播放 | 欧美国产极品一区二区| 中文字幕区自拍偷拍区| 黄色av尤物白丝在线播放网址| 日本一品道在线免费观看| 美女被啪的视频在线观看| 国产麻豆一区二区三区在| 亚洲精品福利视频在线观看| 日韩在线欧美一区二区| 成人午夜视频精品一区| 日韩人妻有码一区二区| 爱在午夜降临前在线观看| 色丁香之五月婷婷开心| 一区二区三区日韩经典| 久久精品福利在线观看| 在线观看国产午夜福利|