Mybatis傳遞多個參數(shù)的三種實現(xiàn)方法
方案一
Dao層的函數(shù)方法
1 Public User selectUser(String name,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>
其中,#{0}代表接收的是dao層中的第一個參數(shù),#{1}代表dao層中第二參數(shù),更多參數(shù)一致往后加即可。
方案二(Map傳值)
Dao層的函數(shù)方法
1 Public User selectUser(Map paramMap);
對應的Mapper.xml
<select id=" selectUser" 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”,”對應具體的參數(shù)值”); paramMap.put(“userArea”,”對應具體的參數(shù)值”); User user=xxx. selectUser(paramMap); }
方案三(推薦)
Dao層的函數(shù)方法
1 Public User selectUser(@Param(“userName”) String name,@Param(“userArea”) String area);
對應的Mapper.xml
<select id=" selectUser" parameterType="map" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Java中的線程安全集合CopyOnWriteArrayList解析
這篇文章主要介紹了Java中的線程安全CopyOnWriteArrayList解析,CopyOnWriteArrayList是ArrayList的線程安全版本,從他的名字可以推測,CopyOnWriteArrayList是在有寫操作的時候會copy一份數(shù)據(jù),然后寫完再設置成新的數(shù)據(jù),需要的朋友可以參考下2023-12-12詳解Java利用ExecutorService實現(xiàn)同步執(zhí)行大量線程
這篇文章主要介紹了Java利用ExecutorService實現(xiàn)同步執(zhí)行大量線程,ExecutorService可以維護我們的大量線程在操作臨界資源時的穩(wěn)定性。2017-03-03解決zuulGateway網(wǎng)關添加路由異常熔斷問題
這篇文章主要介紹了解決zuulGateway網(wǎng)關添加路由異常熔斷問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10java 日志的數(shù)據(jù)脫敏的實現(xiàn)方法
今日給大家介紹一下java 日志的數(shù)據(jù)脫敏的實現(xiàn)方法,可以更好的保護數(shù)據(jù)的安全,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01