如果在動態 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>