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)));
与上进行区分: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));
});
});
```
18.maven 具有传递性,父类引用了并声明版本号,子类则只需引入 无需声明版本号
20.多线程交替打印问题