mybatis中传入参数的几种方式
生活随笔
收集整理的這篇文章主要介紹了
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中传入参数的几种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雄安新区文安智慧新城是毛坯房还是精装修?
- 下一篇: 卫筑石膏自流平怎么样?