日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mybatis中传入参数的几种方式

發布時間:2024/10/12 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mybatis中传入参数的几种方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一種:

Dao層的方法

Public User selectUser(String name,String password);

?

對應的Mapper.xm

  

<select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_password=#{1} </select>

?


第二種:

?

該方法采用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_password=#{userPassword,jdbcType=VARCHAR} </select>

?

??

Service層調用

?

?

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

?

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

?

第三種:

Dao層的方法

Public User selectUser(@param(“userName”)Stringname,@param(“userpassword”)String password);

?

對應的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR} </select>

?

第四種:

mapper.Java:

public List<User> getUserByParam(User use);

?

?

對應Mapper.xml:

<select id="getUserByParam" resultType="com.ray.bean.User" parameterType="com.ray.bean.User" > select * from t_pub_user t <where><if test="{user_name}!=null">t.user_name like CONCAT('%',#{user_name},'%')</if><if test="{user_password}!=null">and t.user_password like CONCAT('%',#{user_password},'%')</if></where>limit #{1},#{2} </select>

?

轉載于:https://www.cnblogs.com/flynnsky/p/7395343.html

總結

以上是生活随笔為你收集整理的mybatis中传入参数的几种方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。