日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

mybatis中mapper接口的参数设置几种方法

發布時間:2025/5/22 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mybatis中mapper接口的参数设置几种方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方法一:忽略parameterType,加@param("xxx")注解

在mapper接口中加上@param("xxx")注解,則在配置文件中直接用即可

List<Map<String, Object>> getDataByTime(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("platformId") Long platformId); <select id="getDataByTime" resultType="java.util.Map">SELECTt.seller_id as sellerId,sum(t.payment_price) as total,FROMtrade_orders tWHEREANDt.platform_id = #{platformId}<if test="startTime != null and startTime != ''">AND<![CDATA[t.order_time >= #{startTime}]]></if><if test="endTime != null and endTime != ''">AND<![CDATA[t.order_time <= #{endTime}]]></if>GROUP BYt.seller_id</select>

方法二:忽略parameterType,不加@param("xxx")注解

用#{index},是第幾個就用第幾個的索引,索引從0開始

List<Map<String, Object>> getDataByTime(String startTime, String endTime, Long platformId); <select id="getDataByTime" resultType="java.util.Map">SELECTt.seller_id as sellerId,sum(t.payment_price) as total,FROMtrade_orders tWHEREANDt.platform_id = #{3}<if test="startTime != null and startTime != ''">AND<![CDATA[t.order_time >= #{0}]]></if><if test="endTime != null and endTime != ''">AND<![CDATA[t.order_time <= #{1}]]></if>GROUP BYt.seller_id</select>

方法三:使用Map封裝參數,parameterType=“hashmap”

封裝好后,直接在配置文件引用#{key}即可

List<Map<String, Object>> getDataByTime(HashMap map); <select id="getDataByTime" parameterType="hashmap" resultType="java.util.Map">SELECTt.seller_id as sellerId,sum(t.payment_price) as total,FROMtrade_orders tWHEREANDt.platform_id = #{platformId}<if test="startTime != null and startTime != ''">AND<![CDATA[t.order_time >= #{startTime}]]></if><if test="endTime != null and endTime != ''">AND<![CDATA[t.order_time <= #{endTime}]]></if>GROUP BYt.seller_id</select>

方法四:使用List封裝參數

mapper配置文件使用foreach標簽循環list

List<Map<String, Object>> getDataByTime(List<String> list); <select id="getXXXBeanList" resultType="java.util.Map">select XX from trade_orders where id in<foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>

轉載于:https://www.cnblogs.com/kobelieve/p/10490635.html

總結

以上是生活随笔為你收集整理的mybatis中mapper接口的参数设置几种方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。