mybatis在动态 SQL 中使用了参数作为变量,必须要用 @Param 注解

如果在动态 SQL 中使用了参数作为变量,那么就要用 @Param 注解,即使你只有一个参数。如果我们在动态 SQL 中用到了 参数作为判断条件,那么也是一定要加 @Param 注解的,例如如下方法:

@Mapper
public interface UserMapper {
    List<User> getUserById(@Param("id")Integer id);
}

xml中:

<select id="getUserById" resultType="org.javaboy.helloboot.bean.User">
    select * from user
    <if test="id!=null">
        where id=#{id}
    </if>
</select>

 

posted @ 2020-08-27 16:53  白熊啊  阅读(1504)  评论(0编辑  收藏  举报