1. 程式人生 > >mybatis增刪改查sql,帶分頁,新增可以返回id

mybatis增刪改查sql,帶分頁,新增可以返回id

**

mybatis增刪改查sql,帶分頁,新增可以返回id

<resultMap type="com.spring.pojo.T_Form" id="T_FormMap">
   <result column="formId" property="formId"/>
   <result column="form_no" property="form_no"/>
   <result column="p_money" property="p_money"/>
   <result column="r_money" property="r_money"/>
   <result column="p_state" property="p_state"/>
   <result column="n_datatime" property="n_datatime"/>
   <result column="p_datatime" property="p_datatime"/>
   <result column="e_state" property="e_state"/>
   <result column="e_datatime" property="e_datatime"/>
   <result column="ShopNO" property="ShopNO"/>
   <result column="ShopName" property="ShopName"/>
   <result column="ShopAddress" property="ShopAddress"/>
   <result column="ShopPhone" property="ShopPhone"/>
   <result column="UnionID" property="UnionID"/>
   <result column="PhoneWX" property="PhoneWX"/>
   <result column="PersonWX" property="personWX"/>
   <result column="addressWX" property="addressWX"/>
   <result column="delivery" property="delivery"/>
   <result column="ShopID" property="ShopID"/>
</resultMap>

<select id="selectAllT_Form" resultMap="T_FormMap">
    select * from(select rownum rom,rn.* from (select * from T_Form t 
	where t.unionID =#{unionId} order by t.formid desc)rn)rom where rom <![CDATA[<]]>= #{pageSize,jdbcType=NUMERIC} and rom <![CDATA[>]]> #{pageNo,jdbcType=NUMERIC}
</select>

<select id="queryT_FormByStatus" resultMap="T_FormMap">
    select * from(select rownum rom,rn.* from (select * from T_Form t  
	where t.unionID =#{unionId} 
    <if test="p_state != null">
		and t.p_state != #{p_state}
	</if>
	<if test="delivery != null">
		and t.delivery = #{delivery}
	</if>
	order by t.formid desc)rn)rom where rom <![CDATA[<]]>= #{pageSize,jdbcType=NUMERIC} and rom <![CDATA[>]]> #{pageNo,jdbcType=NUMERIC}
</select>

<insert id="addT_Form" parameterType="com.spring.pojo.T_Form">
	
	<selectKey keyProperty="formId" order="AFTER" resultType="java.lang.Integer">
		select Tab_T_Form_Sequence.CURRVAL as formId from dual
	</selectKey>
	
	insert into T_Form values(null,#{form_no},#{p_money},#{r_money},#{p_state},#{n_datatime},#{p_datatime},#{e_state},#{e_datatime},#{ShopNO,jdbcType=VARCHAR},#{ShopName,jdbcType=VARCHAR},#{ShopAddress,jdbcType=VARCHAR},#{ShopPhone,jdbcType=VARCHAR},#{UnionID,jdbcType=VARCHAR},#{personWX,jdbcType=VARCHAR},#{PhoneWX,jdbcType=VARCHAR},#{addressWX,jdbcType=VARCHAR},#{delivery,jdbcType=NUMERIC},#{ShopID,jdbcType=NUMERIC})	
			
</insert>

<delete id="deleteT_Form">
	
	delete from T_Form t where t.formid=#{formid}	
			
</delete>

匯入

在寫mapper介面時引數的註解別忘了,最需要注意的是傳的如果是物件也就是新增時千萬別加引數註解!!!