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);
posted @ 2021-02-06 13:50  cchilei  阅读(3512)  评论(0编辑  收藏  举报