Mybatis傳遞多個參數的三種實現方法
方案一
Dao層的函數方法
1 Public User selectUser(String name,String area);
對應的Mapper.xml
<select resultMap='BaseResultMap'> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select>
其中,#{0}代表接收的是dao層中的第一個參數,#{1}代表dao層中第二參數,更多參數一致往后加即可。
方案二(Map傳值)
Dao層的函數方法
1 Public User selectUser(Map paramMap);
對應的Mapper.xml
<select parameterType='map' resultMap='BaseResultMap'> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select>
Service層調用
Private User xxxSelectUser(){ Map paramMap = new hashMap(); paramMap.put(“userName”,”對應具體的參數值”); paramMap.put(“userArea”,”對應具體的參數值”); User user=xxx. selectUser(paramMap);}
方案三(推薦)
Dao層的函數方法
1 Public User selectUser(@Param(“userName”) String name,@Param(“userArea”) String area);
對應的Mapper.xml
<select parameterType='map' resultMap='BaseResultMap'> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. SQL Server中, DateTime (日期)型操作2. 使用SQL語句快速獲取SQL Server數據字典3. SQL Server 2000企業版安裝教程4. Oracle中的高效SQL編寫PARALLEL解析5. 解決mybatis中order by排序無效問題6. mysql數據庫之count()函數和sum()函數用法及區別說明7. MYSQL SQL查詢近7天一個月的數據的操作方法8. Microsoft SQL Server 查詢處理器的內部機制與結構(1)9. SQL SERVER 2005 EXPRESS不能遠程連接的問題10. Mybatis 動態表名+Map參數傳遞+批量操作詳解
