字串以逗號拼接成另一個字串儲存
阿新 • • 發佈:2019-01-07
StringBuilder sb = new StringBuilder(); StringBuilder sbId = new StringBuilder(); for (LMSLabConfigLabClassGroup lmsLabConfigLabClassGroup:lmsLabConfigLabClassGroups) { LabClassLMSGroup labClassLMSGroup = lmsLabConfigLabClassGroup.getLabClassGroup(); if (labClassLMSGroup != null) { if(sb.length() > 0) { sb.append(","); } sb.append(labClassLMSGroup.getName()); if (sbId.length() > 0) { sbId.append(","); } sbId.append(labClassLMSGroup.getId()); } } dto.setGroupName(sb.toString()); dto.setGroupId(sbId.toString());