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));

  

 

posted on 2020-09-16 15:23  滚动的蛋  阅读(174)  评论(0编辑  收藏  举报

导航