Mybatis怎么在mapper中用多个参数
原文地址:https://github.com/mybatis/mybatis-3/wiki/FAQ
How do I use multiple parameters in a 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...
If you want to give them a name use the @param annotation this way:
import org.apache.ibatis.annotations.Param; public interface UserMapper { User selectUser(@Param("username") String username, @Param("hashedPassword") String hashedPassword); }
Now you can use them in your xml like follows:
<select id=”selectUser” resultType=”User”> select id, username, hashedPassword from some_table where username = #{username} and hashedPassword = #{hashedPassword} </select>