pom.xml加入pagehelper插件依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
application.yml加入pagehelper插件配置
#页插件配置:pagehelper分页
pagehelper:
helperDialect: mysql
offsetAsPageNum: true
rowBoundsWithCount: true
reasonable: false
supportMethodsArguments: true
returnPageInfo: true
params: count=countSql
UserMapper.xml错误
<select id="selectPage" parameterType="com.example.springboot.entity.User" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
<where>
<if test="user !=null">
<if test="user.username != null and user.username.trim().length()>0">
<bind name="usernamePattern" value="'%' + user.username + '%'"/>
AND username like #{usernamePattern}
</if>
<if test="user.nickname != null and user.nickname.trim().length()>0">
<bind name="nicknamePattern" value="'%' + user.nickname + '%'"/>
AND nickname like #{nicknamePattern}
</if>
<if test="user.roleId != null and user.roleId != ''">
AND role_id=#{user.roleId}
</if>
<if test="user.id != null and user.id != '' ">
AND id=#{user.id}
</if>
</if>
</where>
UserMapper.xml正确
<select id="selectPage" parameterType="com.example.springboot.entity.User" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
<where>
<if test="user.username != null and user.username.trim().length()>0">
<bind name="usernamePattern" value="'%' + user.username + '%'"/>
AND username like #{usernamePattern}
</if>
<if test="user.nickname != null and user.nickname.trim().length()>0">
<bind name="nicknamePattern" value="'%' + user.nickname + '%'"/>
AND nickname like #{nicknamePattern}
</if>
<if test="user.roleId != null and user.roleId != ''">
AND role_id=#{user.roleId}
</if>
<if test="user.id != null and user.id != '' ">
AND id=#{user.id}
</if>
</where>
userMapper.java
Page<User> selectPage(@Param("user") User user,
@Param("pageNum") int pageNum,
@Param("pageSize") int pageSize);
|