常用

  1. 异常

    • UnsupportedOperationException
  2. 日志

    log.info(LogUtils.gen("message", "key1", value1, "key2", value2));
    log.info(LogUtils.gen("getUser", ImmutableMap.<String, String> builder().put("token", token).put("userId", userId).build()));
    
  3. 对象克隆

    // 一般是从parent克隆出child
    BeanUtils.copyProperties(parent, child);
    
  4. 线程

    new Thread(new Runnable() {
                 @Override
                 public void run() {
                     // code here
                     }
                 }
             }).start();
    
  5. 模板函数

    public <T> void test(T t1) {} // 函数定义
    test(new ClassA()); // 调用
    
  6. 回调函数(Java8的功能)

    public void callbackUsage(Function<String, String> fn) {
     fn.apply(“123”);
    }
    this.callbackUsage(new Function<String, String>() {
     @Override
     public String apply(String t) {
         return null;
     }
    });
    
  7. 注解类获取

    this.getClass().isAnnotationPresent(BizApi.class); // 获取所有引用的判断:BizApi是annotation
    
  8. bean获取

this.service = this.context.getBean(IUserAccountService.class);

for (Map.Entry<String, Object> entry : this.context.getBeansWithAnnotation(BizApi.class).entrySet()) {
            this.apiMap.put(entry.getKey(), (IBizApi) entry.getValue());
}

文件系统

  1. 组合路径
    Path path = Paths.get("path1",  "path2", "fileName");
    File file = path.toFile();
    
wangyaqi.cn all right reserved,powered by Gitbook该文件修订时间: 2020-04-18 15:35:02

results matching ""

    No results matching ""

    results matching ""

      No results matching ""