public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
EasUser condition, String roleIds) throws Exception{
Map<String,Object> map = new HashMap<>();
//将传递过来的角色编号封装到角色集合中
if(roleIds != null && !roleIds.trim().equals("")){
String[] array = roleIds.split(",");
List<EasRole> roles = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
EasRole role = new EasRole();
role.setId(Integer.parseInt(array[i]));
roles.add(role);
}
condition.setRoles(roles);
}
int count = easUserService.getCount();
PageUtil pageUtil = new PageUtil(page,limit);
List<EasUser> list = easUserMapper.getList(condition,pageUtil);
map.put("count",count);
map.put("data",list);
map.put("code",0);
map.put("msg","");
return map;
}
public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
EasUser condition, String roleIds) throws Exception{
Map<String,Object> map = new HashMap<>();
// 查询条件,角色编号集合
//将传递过来的角色编号封装到角色集合中
if(roleIds != null && !roleIds.trim().equals("")){
String[] array = roleIds.split(",");
List<EasRole> roles = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
EasRole role = new EasRole();
role.setId(Integer.parseInt(array[i]));
roles.add(role);
}
condition.setRoles(roles);
}
// 获取EasUser 的总数
int count = easUserService.getCount();
// 分页工具类,page 页数, limit 每页条数
PageUtil pageUtil = new PageUtil(page,limit);
// 带条件的分页查询,获取EasUser的数据集
List<EasUser> list = easUserMapper.getList(condition,pageUtil);
// 返回Map集合,存储 总数,EasUser的数据集,code=0 正常请求 ,msg 提示信息
map.put("count",count);
map.put("data",list);
map.put("code",0);
map.put("msg","");
return map;
}
这段代码定义了一个Java方法,名称为 "list",它接受一些参数并返回一个 "Map<String, Object>" 类型的对象。该方法的主要功能是获取符合条件的 "EasUser" 列表,并封装到一个HashMap中。
首先,该方法接受三个参数:"page"、"limit" 和 "condition",它们分别表示当前页码,每页的记录数和查询条件(类型为 "EasUser")。
其次,该方法还接受一个名为 "roleIds" 的字符串参数,表示用户的角色编号。如果 "roleIds" 不为空,则将它拆分为多个角色编号,并将它们封装为一个 "EasRole" 列表,并将 "EasUser" 对象的 "roles" 属性设置为该列表。
接下来,该方法调用 "easUserService.getCount()" 方法获取用户记录总数,并实例化一个 "PageUtil" 对象来进行分页查询。再调用 "easUserMapper.getList()" 方法获取符合条件的用户列表,并将返回的数据封装为一个 "Map<String, Object>" 对象,其中键值 "count" 存储记录总数,键值 "data" 存储查询结果,键值 "code" 和 "mag" 存储状态码和状态信息。
最后,该方法将封装后的 "Map<String, Object>" 对象返回。
已为你加好相关注释
/**
* 返回用户列表的方法,包括分页信息、查询条件和角色集合
*
* @param page 默认为1的页码数
* @param limit 默认为10的每页显示的数据条数
* @param condition 查询条件,包括用户名称、所属部门等信息
* @param roleIds 角色编号集合,用逗号隔开
* @return 返回Map对象,包括用户列表信息和分页信息等
* @throws Exception 异常处理
*/
public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
EasUser condition, String roleIds) throws Exception{
// 创建一个HashMap对象,用于存储返回的用户列表信息和分页信息等
Map<String,Object> map = new HashMap<>();
// 如果传递过来的角色编号不为空,则将其封装到角色集合中
if(roleIds != null && !roleIds.trim().equals("")){
String[] array = roleIds.split(",");
List<EasRole> roles = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
EasRole role = new EasRole();
role.setId(Integer.parseInt(array[i]));
roles.add(role);
}
// 将封装好的角色集合设置到查询条件中
condition.setRoles(roles);
}
// 获取用户记录的总数
int count = easUserService.getCount();
// 创建分页工具对象
PageUtil pageUtil = new PageUtil(page,limit);
// 查询符合条件的用户记录列表
List<EasUser> list = easUserMapper.getList(condition,pageUtil);
// 将用户记录总数、用户记录列表、状态码和提示信息封装到Map对象中
map.put("count",count);
map.put("data",list);
map.put("code",0);
map.put("msg","");
// 返回Map对象
return map;
}