1. 程式人生 > >mybatis的基本的增刪改查單條

mybatis的基本的增刪改查單條

<table sqlname="catetory">


    <operation name="queryByCatetoryId">
        <sql>
            select 
            catetory_id,
            catetory_name,
            from catetory
            where
            catetory_id = ?
        </sql>
    </operation>


    <operation name="queryByMerchantId" multiplicity="many">
        <extraparams>
            <param name="merchantId" javatype="java.lang.String"/>
        </extraparams>
        <sql>
            select 
            catetory_id,
            catetory_name,
            from catetory
        </sql>
        <sqlmap>
            <![CDATA[
			 select
            catetory_id,
            catetory_name,
            from catetory
			WHERE
			merchant_id =  #merchantId#
			ORDER BY catetory_id desc
			]]>
        </sqlmap>
    </operation>

<operation name="queryByMerIdAndName" multiplicity="many">
        <extraparams>
            <param name="merchantId" javatype="java.lang.String"/>
            <param name="catetoryName" javatype="java.lang.String"/>
            <param name="delFlag" javatype="java.lang.String"/>
        </extraparams>
        <sql>
            select 
            catetory_id,
            catetory_name,
            from catetory
        </sql>
        <sqlmap>
            <![CDATA[
			 select 
            catetory_id,
            catetory_name,
            from catetory
			WHERE
			merchant_id =  #merchantId#
			AND catetory_name= #catetoryName#
			<dynamic>
				    <isNotEmpty prepend="and" property="delFlag">
					del_flag = #delFlag#
					</isNotEmpty>
			</dynamic>

			]]>
        </sqlmap>
    </operation>

//批量查詢
<operation name="queryListByCatetoryIds" multiplicity="many">
        <extraparams>
            <param name="catetoryIdList" javatype="java.util.List"/>
        </extraparams>
        <sql>
            <![CDATA[
	 select
            catetory_id,
            catetory_name,
            from catetory
	  ]]>
        </sql>
        <sqlmap>
            <![CDATA[
	 select 
            catetory_id,
            catetory_name,
            from catetory
				where catetory_id IN
				<iterate prepend="(" close=")" conjunction=",">
                    #[]#
                </iterate>
             ORDER BY id desc
	 	 ]]>
        </sqlmap>
    </operation>

    <operation name="insert" paramType="object">
        <sql>
            insert into
            catetory 
            (catetory_id,
            catetory_name)
            values
            (?,?)
        </sql>
    </operation>

    <operation name="update" paramType="object">
        <sql>
            update
            catetory
            set modified=now(),
            catetory_name=?,
            sort=?,
            where catetory_id = ?
        </sql>
    </operation>

</table>

基本的mybatis的增刪改查