Mybatis怎么在mapper中用多个参数

来源:互联网 发布:杭州小知科技 知乎 编辑:程序博客网 时间:2024/05/01 11:33

原文地址: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>
0 0
原创粉丝点击