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