Mybatis传递多个参数的几种方式

原文地址:
https://mp.weixin.qq.com/s?__biz=MzI3ODcxMzQzMw==&mid=2247485137&idx=1&sn=8b6fa49dccc01b040c24749375e88a4f&chksm=eb5383e7dc240af15943519938f33da919436464b3182a70fec0ed3196a8761bf85594c6c0e6&scene=21#wechat_redirect

1.Mybatis提供的注释@Param

public User selectUser(@Param("userName") String name, int @Param("deptId") deptId);

<select id="selectUser" resultMap="UserResultMap">
    select * from user
    where user_name = #{userName} and dept_id = #{deptId}
</select>

2.Map传参

public User selectUser(Map<String, Object> params);

<select id="selectUser" parameterType="java.util.Map" resultMap="UserResultMap">
    select * from user
    where user_name = #{userName} and dept_id = #{deptId}
</select>

3.Java Bean传参

public User selectUser(User user);

<select id="selectUser" parameterType="com.test.User" resultMap="UserResultMap">
    select * from user
    where user_name = #{userName} and dept_id = #{deptId}
</select>

4.顺序传参

public User selectUser(String name, int deptId);

<select id="selectUser" resultMap="UserResultMap">
    select * from user
    where user_name = #{0} and dept_id = #{1}
</select>
posted @ 2021-06-15 15:59  爱饮凉水  阅读(103)  评论(0编辑  收藏  举报