国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Mabatis傳多個參數的方法

2024-07-21 02:51:42
字體:
來源:轉載
供稿:網友

第一種方案 

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層調用

PRivate User xxxSelectUser(){Map paramMap=new hashMap();paramMap.put(“userName”,”對應具體的參數值”);paramMap.put(“userArea”,”對應具體的參數值”);User user=xxx. selectUser(paramMap);}

個人認為此方法不夠直觀,見到接口方法不能直接的知道要傳的參數是什么。

第三種方案

Dao層的函數方法
Public User selectUser(@param(“userName”)Stringname,@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層方法就知道該傳什么樣的參數,比較直觀,個人推薦用此種方案。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 什邡市| 嘉禾县| 绥江县| 华宁县| 紫阳县| 乌兰察布市| 和龙市| 临泉县| 嵩明县| 罗甸县| 湘潭县| 武鸣县| 永川市| 唐河县| 江北区| 静宁县| 绿春县| 焦作市| 兴宁市| 芦山县| 栾城县| 剑阁县| 朝阳县| 贵港市| 墨竹工卡县| 重庆市| 德格县| 绵阳市| 天气| 洛扎县| 梨树县| 民勤县| 城步| 西安市| 蕲春县| 东丽区| 德清县| 元朗区| 嵩明县| 九寨沟县| 孟津县|