Mybatis-plus IPage paging common problems (pit)
Tips before viewing:
The IDEA version used in this article is ultimate 2019.1, and the JDK version is 1.8.0_141.
1.TooManyResultsException
Recently, when using the IPage plug-in of Mybatis-plus for paging, the following inexplicable error occurred
Resolved [org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 6]
Then I checked the Controller, Service, Mapper, Mapper.xml I wrote, and the result was nothing. The following are my Mapper and Mapper.xml (the content is roughly the same)
Mapper
public interface ExampleMapper {
IPage<EntityDto> selectEntityAndPage(@Param("param") Entity param, Page<Entity> page);
}
The select part of Mapper.xml
<select id="selectEntityAndPage" parameterType="cn.com.example.enetity.Entity " resultType="cn.com.example.dto.EntityDto">
select id, name from table
</select>
Baidu discovered this deep pit after a while
The page parameter in mybatis-plus is not in the first position, and the returned result set receiving object is not considered a collection, but it is no problem in the first position.
So I rewritten the order of Mapper parameters
IPage<EntityDto> selectEntityAndPage(Page<Entity> page, @Param("param") Entity param);
problem solved.