Mybatis 傳入多個引數查詢資料 (3種方法)
第一種方案
DAO層的函式方法
public User selectUser(String name,String area);
對應的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{0} and user_area=#{1}
</select>
其中,#{0}代表接收的是dao層中的第一個引數,#{1}代表dao層中第二引數,更多引數一致往後加即可。第二種方案 此方法採用Map傳多引數.
Dao層的函式方法
public User selectUser(Map paramMap);
對應的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>
Service層呼叫
public User xxxSelectUser(){ Map paramMap=new hashMap(); paramMap.put(“userName”,”對應具體的引數值”); paramMap.put(“userArea”,”對應具體的引數值”); User user=xxx.selectUser(paramMap); }
個人認為此方法不夠直觀,見到介面方法不能直接的知道要傳的引數是什麼。
第三種方案
Dao層的函式方法
public User selectUser(@Param("userName")String name,@Param("userArea")String area);
對應的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select>
個人覺得這種方法比較好,能讓開發者看到dao層方法就知道該傳什麼樣的引數,比較直觀,個人推薦用此種方案。
轉載自: http://www.2cto.com/database/201409/338155.html
相關推薦
Mybatis 傳入多個引數查詢資料 (3種方法)
據我目前接觸到的傳多個引數的方案有三種。 第一種方案 DAO層的函式方法 public User selectUser(String name,String area); 對應的Mapper.xml <select id="selectUser" result
MyBatis傳入多個引數,傳入陣列和列表資料的處理
java定義: List<RoleEx> selectByRoleIdList(@Param("roles")String[] roles); List<RoleEx
mybatis 根據多個id查詢資料 foreach標籤
//根據裝置多個id獲取裝置資訊 public List<Devices> getDevicesAll(@Param("devicesIds") String[] devicesIds); <select id="getDevicesAll" resultMap
mybatis傳入多個引數
方案一: public List<XXXBean> getXXXBeanList(String xxId, String xxCode); <select id="getXXXBeanList" resultType="XXBean"> select t.*
mybatis 傳入多個引數
List<BoReview> check(@Param("flows") String[] flows, @Param("id") long id); <select id="check" resultMap="BaseResultMap" > select *
(轉載)MyBatis傳入多個引數的問題
原文地址:https://www.cnblogs.com/mingyue1818/p/3714162.html 一、單個引數: public List<XXBean> getXXBeanList(String xxCode); <select id="getX
Mybatis 傳入多個引數的方法
1.由於是多引數那麼就不能使用parameterType, 改用#{index}是第幾個就用第幾個的索引,索引從0開始 <update id="modifyPwd">
MyBatis 傳入多個引數時,如何處理
方式一:通過使用索引方式,來指定想傳入的引數,#{index} 索引從0開始。 DAO介面 Mybatis配置 注意: 1.由於是多引數傳入,所以不需要對parameterType進行配置
MyBatis傳入多個引數的問題
<select id="getSysInfo" parameterType="java.util.Map" resultType="SysWeb"> select t.sysSiteId, t.siteName, t1.mzNum as siteTagNum, t1.mzName as sit
MyBatis傳入多個引數筆記(一)
一、傳入一個引數 1、Controller裡面的方法 selectUser(@Param("user_id") int user_id) 2、Dao層的方法 public Li
MyBatis 呼叫Mapper.xml傳入多個引數
引用處: https://www.cnblogs.com/mingyue1818/p/3714162.html 單個引數: public List<XXBean> getXXBeanList(String xxCode); <select id="get
mybatis傳多個引數(不使用@param註解情況下),3.4.2版本之後出現#{0}-#{n}引數繫結異常
解決方案: 在mybatis配置檔案中宣告setting屬性的useActualParamName 引數值為false **
mybatis傳多個引數(不使用@param註解情況下),3.4.2版本之後使用#{0}-#{n}引起的引數繫結異常,以及settings屬性中useActualParamName的作用。
解決方案: mybatis的xml配置檔案中宣告settings屬性的useActualParamName引數值為false <setting name="useActualParamName" value="false" /> 程式碼展示
Mybatis 如何傳入多個引數
在Mybatis中,xml配置檔案裡有如下程式碼: <insert id="doInsertUser" parameterType="User"> INSERT INTO R_User(user_name, password, phone, email,
11、Mybatis處理傳入多個引數
一、 當傳入一個引數時,mybatis直接把輸入的引數繫結到#{} 中的變數中。但是mybatis如何處理傳入多個引數的情況呢? 例如一個庫表users,有id、name、age三個欄位,現在通過傳入id、name兩個引數來查詢整條記錄。對應的介面如下:
在Mybatis中使用註解@多個引數查詢
@Select("SELECT * FROM wc_homework WHERE organization_id=#{classId} ORDER BY createtime DESC LIMIT #{start},#{count}") @Results({
mybatis傳入多個參數
varchar tty indent span get map類型 bean if判斷 基於 在開頭: 需要查閱本文的基本都是需要傳入多個參數的,這裏記住一句話:無論你傳的參數是什麽樣的,最後mybtis都會將你傳入的轉換為map的,那麽既然這樣,當我們要傳入多個參數時,
mybatis 傳遞多個引數(xml對映配置二)
方法名中有多個引數 map方式 當多個變數傳入時候,設定入參為map型別,本質上map儲存了入參的鍵值對 優點:幾乎使用所有場景 缺點:業務性質太差,可讀性太差,必須要依賴於接口才能明白入參 &
postgresql Java JDBC 一次性傳入多個引數到 in ( ?) - multple/list parameters
經常不清楚需要傳入多少個引數到 IN () 裡面,下面是簡單方法: 方法 1 - in ( SELECT * FROM unnest(?)) ) Integer[] ids={1,2,3};
mybatis封裝多個引數的方法總結
1 單個引數 <select id="get" parameterType="long" resultType="string"> select name from test where id=#{id}