How do I use multiple parameters in a mapper?
mybatis3中在mapper接口方法中如何使用多参
Java reflection does not provide a way to know the name of a method parameter so MyBatis names them by default like: param1, param2...
对于方法参数的名称,Java反射没有提供方法去获得这个参数的名字,所以mybatis3 就把这些参数按照约定的方式命名为
param1, param2...
If you want to give them a name use the @param annotation this way:
如果哦你想提供个有意义的名字,那就用 @param注解吧.
<span style="font-size:18px;">import org.apache.ibatis.annotations.Param;
public interface UserMapper {
User selectUser(@Param("username") String username, @Param("hashedPassword") String hashedPassword);
}</span>
Now you can use them in your xml like follows:
<span style="font-size:18px;"><select id=”selectUser” resultType=”User”>
select id, username, hashedPassword
from some_table
where username = #{username}
and hashedPassword = #{hashedPassword}
</select></span>