@PostContruct是spring框架的注解,在方法上加该注解会在项目启动的时候执行该方法,也可以理解为在spring容器初始化的时候执行该方法。 @Componentpublic class SettingManager { @Inject private SettingService settingService; @Inject private SettingItemService settingItemService; private static SettingManager settingManager; private Long userId; private ListsettingItems; @PostConstruct public void init() { settingManager = this; }}
map的高级用法
public StatictisDataWrapper(Map> map) { this.list = new ArrayList<>(); map.forEach((string, statistics) -> list.add(new StatictisData(string, statistics))); }
map获取不到就设定默认值String metastore = map.getOrDefault("hive.metastore.uris", "");
default的使用
@Target({TYPE,METHOD,FIELD,CONSTRUCTOR}) @Retention(RetentionPolicy.RUNTIME) public @interface TestA { String name(); int id() default 0; Classgid(); }
stream 聚合:
public MapaggCount() { return this.getNotNullValues().stream().collect(Collectors.groupingBy(s -> s, Collectors.counting())); }
FileUtil的用法
/** * 文件操作 **/ private static void writeFile(File file, String content) { try { FileUtils.writeStringToFile(file, content, "UTF-8"); } catch (IOException e) { logger.error("Exception:write title file error!", e); } } private static void writeLines(File file, Listlines) { try { FileUtils.writeLines(file, "UTF-8", lines); } catch (IOException e) { logger.error("Exception:write title file error!", e); } } private static String readFile(File file) { try { return FileUtils.readFileToString(file, "UTF-8"); } catch (IOException e) { logger.error("Exception:read type file error", e); return ""; } } private static List readLines(File file) { try { return FileUtils.readLines(file, "UTF-8"); } catch (IOException e) { logger.error("Exception:read type file error", e); return new ArrayList<>(); } }
重写借口的方法 public interface ProcessStreamHandler { void handle(String var1);} ProcessStreamHandler handler = (line) -> { FileUtil.writeFile(logFile, line + "\r\n", true); }
ProcessUtil processUtil = new ProcessUtil(handler);
for用法
for(var5 = sparkAction.getAppArgs().iterator(); var5.hasNext(); launcher = launcher.addAppArgs(new String[]{arg})) { arg = (String)var5.next(); }