mybatis dao层到xml映射文件正确的传参数方式
根据参数名字映射
public interface UserDao extends BaseMapper<User>
{
List<User> listUser(@Param("userName") String userName,@Param("password") String password);
}
根据@Param(“userName”) 中的名称与xml映射文件的#{userName}名称对应,此时在select中可以不用写paramType
<select id="listUser" resultType="com.reuse.customer.entity.User" >
select * from user
<where>
<if test="userName!=null and userName.trim()!=""">
user_name=#{userName}
</if>
<if test="password!=null and password.trim()!=""">
and password=#{password}
</if>
</where>
</select>
注意在<where>条件语句前面不要随意写注释,否则容易报错。


