国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Mybatis傳遞多個參數的三種實現方法

瀏覽:6日期:2023-10-24 10:09:36

方案一

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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 凌云县| 汉阴县| 彩票| 清丰县| 宝坻区| 九寨沟县| 宜章县| 勐海县| 南靖县| 介休市| 青龙| 聊城市| 怀仁县| 扬州市| 锡林浩特市| 普安县| 平谷区| 云林县| 晋江市| 凤庆县| 靖州| 东明县| 睢宁县| 瓦房店市| 雷波县| 云南省| 且末县| 苏州市| 开远市| 安岳县| 平山县| 贵港市| 宜兰市| 铜陵市| 德清县| 衡水市| 乳山市| 微山县| 紫金县| 博乐市| 玉田县|