Java 8 新特性
@Override public List<String> getUserRoles(String username) {
//找到以ROLE_开头的,并且映射为字符串数组 return userDetailsService.loadUserByUsername(username).getAuthorities().stream() .filter((GrantedAuthority a) -> a.getAuthority().startsWith("ROLE_")) .map((GrantedAuthority a) -> a.getAuthority().substring(5)) .collect(Collectors.toList()); }
2、收集为Map
Map<String, String> buMap = buList.stream().collect(Collectors.toMap(OrgHierarchy::getBuName, OrgHierarchy::getBuUniteCode, (key1, key2) -> key1));