1. 程式人生 > >sqlMap.xml中的查詢返回情況

sqlMap.xml中的查詢返回情況

1、直接返回單列的list , resultType為list中元素的型別

<!-- 返回esc_orderidlist -->

<select id="selectActutalOrderRecords" parameterType="java.util.Map" resultType="java.lang.String" >

<![CDATA[

         SELECT t.esc_orderidfromt_ws_sett_data_record t 

         where t.create_time  >=to_date(#{begdate},'yyyy-MM-dd') and t.create_time < to_date( #{enddate},'yyyy-MM-dd')

         group by  t.esc_orderid

]]>

</select>

2、直接返回物件的list, resultType為物件型別

<!--

     1parameterTypemap2.put("list",slist); 將引數為list轉換為in中的內容

     2、返回 FailureOrderDto物件的list

 -->

<select id="selectOrderFailureReasons" parameterType="java.util.Map" resultType="com.ule.dto.FailureOrderDto"

>

SELECTTT.ESC_ORDERID AS ECSORDERID,TT.REPLY_DESC AS REMARK,DECODE(TT1.VERSION,'5','5.0',4,'4.0','3','3.0',3.0)  AS FVERSION FROM                  T_WS_REPLY_RECORDTT,T_WS_SETT_DATA_RECORD TT1

    WHERE TT.ESC_ORDERID=TT1.ESC_ORDERID AND TT.ESC_ORDERID IN 

<foreach collection="list"item="item" index

="index"open="(" close=")"separator=",">

        #{item}

</foreach>

</select>

3、直接返回resultType型別Integer

<!-- 直接返回Integer -->

<select id="countNumOfInvoiceInfo" parameterType="java.util.Map" resultType="java.lang.Integer">

                selectcount(1) from Invoice_Info ii where 1 = 1

<if test="escOrderid !=null">

                     andii.esc_orderid = #{escOrderid}

</if>

</select>

4、直接返回resultType型別String

<!-- 直接返回String -->

<select id="queryEscOrderid" parameterType="java.util.Map"resultType="java.lang.String">

                selectesc_orderid from Invoice_Info ii where and id = #{id}

</select>

5、返回的list中是map物件,以前最常用的一種 ,這裡的resultType給為了resultMap

<!-- 返回的list中是map物件,propertymapkey -->

<resultMap id="queryInvoiceEWM" type="java.util.HashMap" >

<result column="id" property="id"/>

<result column="invoice_no" property="invoiceNo" />

<result column="amount" property="amount"/>

<result column="ewm" property="ewm"/>

<result column="bussiness_type" property="bussinessType" />

</resultMap>

<select id="queryInvoiceEWM" parameterType="java.util.Map" resultMap="queryInvoiceEWM">

   select

   i.id,

   i.invoice_no,

   i.amount,

   dbms_lob.substr(h.ewm) ewm,

   i.bussiness_type

   from invoice_handle h ,invoice_info i

   where h.valid_flag=1

   and i.valid_flag=1

   and i.status = '2'

   and i.type = '0'

   and i.invoice_no = h.invoice_no

   and i.esc_orderid=#{escOrderid}

</select>

6、總結:

     a如果查詢結果是只有一行一列,則可以直接用resultType型別接收;

      b、如果查詢的資料是多行一列,則返回回resultType型別的list

      C、如果查詢結果是一行多列、多行多列,則返回的list中是行物件或行的Map