3.3.9 多参数传递

九、多参数传递

通过接口绑定解决多参数的传递

1. 方式一

(1) 接口中定义方法

User selByUP(String username, String password);

(2) 映射文件中提供对应的标签. 此时, SQL 语句中获取方式有两种, 通过#{index} 或#{param+数字} 的方式.

<select id="selByUP" resultType="user">

select * from t_user where username=#{0} and password=#{1}

</select>

2. 方式二

(1) 接口中定义方法, 参数中使用 @Param 注解设定参数名用于在 SQL 语句中使用.

User selByUP(@Param("username") String username, @Param("password") String password);

(2) 映射文件中提供对应的标签. 此时, SQL 语句中获取方式有两种, 通过#{参数名称} 或#{param+数字} 的方式.

<select id="selByUP" resultType="user">

select * from t_user where username=#{username} and password=#{password}

</select>

猜你喜欢

转载自www.cnblogs.com/kendyho/p/10847935.html
今日推荐