public List<User> selectUsers(Integer role, PageSort page) { log.info("批量查询用户信息,查询的角色权限:" + role); List<User> usersList = new ArrayList<User>(); int offset = (page.getPageNum() - 1) * page.getPageSize(); int limit = page.getPageSize(); RowBounds rowBounds = new RowBounds(offset, limit); List<User> userList = userInfoMapper.selectByRoleAndPage(role, rowBounds); return usersList; } @SelectProvider(type = UserSqlProvider.class, method = "selectByRoleAndPage") List<User> selectByRoleAndPage(@Param("role") Integer role, RowBounds rowBounds); public class UserSqlProvider { public String selectByRoleAndPage(Integer role, RowBounds rowBounds) { String sql = "SELECT * FROM user WHERE 1=1"; if (role != -1) { sql += " AND role = #{0}"; } sql += " LIMIT #{1.offset}, #{1.limit}"; return sql; } }方法selectByRoleAndPage没有关联上
时间: 2024-03-17 19:41:48 浏览: 75
selectUsers方法,应该在UserSqlProvider类中添加@Param注解来指定参数名称,如下所示:
```
public String selectByRoleAndPage(@Param("role") Integer role, @Param("rowBounds") RowBounds rowBounds) {
String sql = "SELECT * FROM user WHERE 1=1";
if (role != -1) {
sql += " AND role = #{role}";
}
sql += " LIMIT #{rowBounds.offset}, #{rowBounds.limit}";
return sql;
}
```
同时,在selectUsers方法中,应该将userList赋值给usersList,如下所示:
```
public List<User> selectUsers(Integer role, PageSort page) {
log.info("批量查询用户信息,查询的角色权限:" + role);
List<User> usersList = new ArrayList<User>();
int offset = (page.getPageNum() - 1) * page.getPageSize();
int limit = page.getPageSize();
RowBounds rowBounds = new RowBounds(offset, limit);
List<User> userList = userInfoMapper.selectByRoleAndPage(role, rowBounds);
usersList.addAll(userList);
return usersList;
}
```
阅读全文