欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mybatis查詢返回兩個(gè)或多個(gè)參數(shù)問題

 更新時(shí)間:2023年06月28日 16:18:31   作者:居居很有愛  
這篇文章主要介紹了Mybatis查詢返回兩個(gè)或多個(gè)參數(shù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

mybatis查詢返回兩個(gè)或多個(gè)參數(shù)

xml中的resultType設(shè)為map:

<select id="selectWeekData" ?resultType="map">
? ? ? ? SELECT count,date FROM yqfk_qjsq
<select>

dao中的返回設(shè)置為:List<Map<Object,Object>>

public List<Map<Object,Object>> selectWeekData();

遍歷查詢出來的結(jié)果為:

{date=2022-04-14, count=1}
{date=2022-04-11, count=2}
{date=2022-04-05, count=2}

這只是其中一個(gè)方法,

另一種方法就是重新定義一個(gè)新的類,在里面只存放要返回的字段。

這里就不寫了!

當(dāng)mybatis有多個(gè)參數(shù)時(shí)并增加判斷的寫法

當(dāng)mybatis有多個(gè)參數(shù)時(shí),mapper.java文件即dao層必須寫上@Param注解

List<AddressBean> listAddressByDate(@Param("startDate")String startDate, @Param("endDate")String endDate);

然后在xml文件里用where if判斷是否為空,注意if的test判斷里不要加#{  }

<select id="listAddressByDate" resultType="cn.zwkj.beans.AddressBean" parameterType="String">
? ? ? ? select biaozhunmingcheng,hanyuduyin,dzzzcode,dengjishijian,id from t_placecommon
? ? ? ? <where>
? ? ? ? ? ? <if test="startDate!=null and startDate != '' ">
? ? ? ? ? ? ? ? and to_char(dengjishijian,'yyyy-MM-dd') <![CDATA[>=]]> #{startDate}
? ? ? ? ? ? </if>
? ? ? ? ? ? <if test="endDate!=null and endDate != '' ">
? ? ? ? ? ? ? ? and to_char(dengjishijian,'yyyy-MM-dd') <![CDATA[<=]]> #{endDate}
? ? ? ? ? ? </if>
? ? ? ? </where> ? ? ? ? ? ? ? ??
</select>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論