java中循环拼接字符串

时间:2023-02-26 21:30:29

在java中,查询某工号下用户的权限值,拼接为字符串,返回

表中数据结构如下:

java中循环拼接字符串

查询结果如下:

java中循环拼接字符串java中循环拼接字符串

拼接permissionCode值;

代码如下:

List<UpsUserRoleMenu> roleMenus = upsUserRoleMapper.selectRoleAndSysId(userId);
String roleId = null;
Integer sysId =null;
for (UpsUserRoleMenu upsUserRoleMenu : roleMenus) {
roleId = upsUserRoleMenu.getRoleId();
sysId = upsUserRoleMenu.getSysId();
try {
List<UpsRolePermissionDataparams> menus_list = upsRolePermissionDataParamersMapper
.selectByUserId(Integer.valueOf(roleId),sysId);
StringBuffer permission = new StringBuffer();
if(null != menus_list && menus_list.size() != 0){
for(int i=0;i<menus_list.size(); i++){
UpsRolePermissionDataparams menu = menus_list.get(i);
if(i == 0){
permission.append(menu.getPermissionCode());
}else{
permission.append(","+menu.getPermissionCode());
}
}
upsUserRoleMenu.setPermission(permission.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}

结果如下图:

java中循环拼接字符串