开发记录

190 阅读1分钟

1.@EventListener
2.1 如何自定义注解 1
2.2 如何自定义注解 2
3.Spring 使用@Autowired注解注入集合类List,Map替代ApplicationContextAware获取Bean:策略模式的体现
4.JAVA8 stream

JSONArray jsonArray = new JSONArray();
Result result = new Result(666, "haha", jsonArray);
Result result2 = new Result(701, "xixi", jsonArray);
List<Result> resultList = new ArrayList<>();
resultList.add(result);
resultList.add(result2);
List<String> res2 = resultList.stream()
        .map(Result::getMessage)
        .collect(Collectors.toList());
List<Result> res3 = resultList.stream()
        .filter(result1 -> result1.code > 700)
        .collect(Collectors.toList());
//log.error(JSON.toJSONString(res3));
List<String> ree = new ArrayList<>();
Optional.ofNullable(resultList)
        .ifPresent(results -> {
            List<String> rr = results.stream()
                    .filter(result1 -> result1.getCode() > 700)
                    .map(Result::getMessage)
                    .collect(Collectors.toList());
            ree.addAll(rr);
        });
boolean flag = resultList.stream().allMatch(result1 -> result1.code > 700);
boolean flag2 = resultList.stream().anyMatch(result1 -> result1.code > 700);
log.error(JSON.toJSONString(flag));
log.error(JSON.toJSONString(flag2));
log.error(JSON.toJSONString(ree));


Map<String, SeckillGoodsUnit> data = rpcResponse.getData();
Map<String, Map<String, Object>> result = new HashMap<>();
data.forEach((key, value) -> result.put(key, setSeckillGoodsUnitInfo(value)));

5.JAVA :: 运算符

6.JsonObject 映射为实体类

与上进行区分:getObject("",new TypeReference<>(){});

```
String jsonmatch =  "{\n" +
        "  "query": {\n" +
        "    "bool": {\n" +
        "     \n" +
        "      "must": [\n" +
        "        {\n" +
        "          "match": {\n" +
        "            "yjhx": "2"\n" +
        "          }\n" +
        "        }\n" +
        "      ]\n" +
        "    }\n" +
        "  },\n" +
        "  "_source": [\n" +
        "    "main_sku_id"\n" +
        "  ]\n" +
        "}";
JSONObject param = JSON.parseObject(jsonmatch);
JSONObject boolQuery = param.getJSONObject("query").getJSONObject("bool");
List<JSONObject> must = boolQuery.getObject("must", new TypeReference<List<JSONObject>>(){});
must.stream().forEach(m->{
    Map<String,Object> matchMap = m.getObject("match",new TypeReference<Map<String,Object>>(){});
    matchMap.keySet().stream().forEach(key->{
        System.out.println("match key:"+key+",value:"+matchMap.get(key));
    });
});
```
  1. spring学习之 @Configuration的使用及其原理

  2. 可通过线程池实现异步调用

  3. 规则引擎 easy-rules

  4. 定时任务

  5. @Accessors(chain = true)

  6. @RequiredArgsConstructor用法

  7. SpringBoot常用注解@RestControllerAdvice

  8. 过滤器(Filter)与拦截器(Interceptor )区别

  9. 网络IO模型

  10. http协议与TCP协议区别

  11. JMM java内存模型

  12. spring bean生命周期 [spring-BeanNameAware的使用]


18.maven 具有传递性,父类引用了并声明版本号,子类则只需引入 无需声明版本号

19.spring bean 的生命周期

20.多线程交替打印问题