记录比较实用,但是又比较冷门,容易忘记的一些函数

org.springframework.util.AntPathMatcher.match

判断路径是否匹配

antPathMatcher.match("/test/{test}", "test/1") // true

org.apache.commons.text.StringSubstitutor

org.springframework.util.PropertyPlaceholderHelper

从字符串中提取变量值, 用于处理占位符的替换

PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("{", "}");

String templateContent = "【{signName}】你好, {hello}";

Properties properties = new Properties();
properties.put("hello", "jojo");
properties.put("signName", "签名");
String content = propertyPlaceholderHelper.replacePlaceholders(templateContent, properties);
System.out.println(content);


Map<String, String> properties2 = new HashMap<>();
properties2.put("hello", "jojo");
properties2.put("signName", "签名");
StringSubstitutor sub = new StringSubstitutor(properties2, "{", "}");
System.out.println(sub.replace(templateContent));

StopWatch

guava apache spring 都有这个类

StopWatch stopWatch = new StopWatch();
stopWatch.start("task1");
Thread.sleep(1000);
stopWatch.stop();

java.util.Collections.shuffle

随机从list中取出指定个数的元素 抽奖场景

Collections.shuffle(list, 12);

org.springframework.web.util.UriComponentsBuilder

UriComponentsBuilder.fromUriString
posted @ 2021-07-12 20:17  随风森林  阅读(109)  评论(0)    收藏  举报