mybatis-plus IPage分頁多參數查詢踩坑


1.Mapper

IPage<Entity> findById(@Param("id") Integer id, Page<Entity> page );

2.Mapper.xml

<select id="findById" resultType="com.xxx.Entity" parameterType="com.xxx.Entity">
    select
    <include refid="invalid"/>
    from table_name
    where
    id = #{id}
</select>

3. TooManyResultsException

org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 10

問題解決

mybatis-plus 中page參數不在第一個位置,返回的結果集接收對象不被認為是一個集合,而放在第一位就沒有問題。所以正確的寫法是

IPage<Entity> findById(Page<Entity> page, @Param("id") Integer id);


免責聲明!

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



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