Mybatis傳遞多個(gè)參數(shù)的三種實(shí)現(xiàn)方法
方案一
Dao層的函數(shù)方法
1 Public User selectUser(String name,String area);
對(duì)應(yīng)的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層中的第一個(gè)參數(shù),#{1}代表dao層中第二參數(shù),更多參數(shù)一致往后加即可。
方案二(Map傳值)
Dao層的函數(shù)方法
1 Public User selectUser(Map paramMap);
對(duì)應(yīng)的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層調(diào)用
Private User xxxSelectUser(){ Map paramMap = new hashMap(); paramMap.put(“userName”,”對(duì)應(yīng)具體的參數(shù)值”); paramMap.put(“userArea”,”對(duì)應(yīng)具體的參數(shù)值”); User user=xxx. selectUser(paramMap);}
方案三(推薦)
Dao層的函數(shù)方法
1 Public User selectUser(@Param(“userName”) String name,@Param(“userArea”) String area);
對(duì)應(yīng)的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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Windows10環(huán)境安裝sdk8的圖文教程2. Windows系統(tǒng)徹底卸載SQL Server通用方法(推薦!)3. Oracle rac環(huán)境的數(shù)據(jù)庫(kù)導(dǎo)入操作步驟4. MYSQL(電話號(hào)碼,身份證)數(shù)據(jù)脫敏的實(shí)現(xiàn)5. Sql在多張表中檢索數(shù)據(jù)的方法詳解6. Navicat for MySQL的使用教程詳解7. Mysql中的日期時(shí)間函數(shù)小結(jié)8. mysql查詢的控制語句圖文詳解9. debian10 mariadb安裝過程詳解10. SQL Server2022安裝圖文教程(最新推薦)
