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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM