在进行消息拼装或者其他字符串拼装的时候很麻烦,可使用mybatis现有的解析包来处理“占位符模板”就会变得极为简单,引用包org.apache.ibatis.parsing
- 默认
Properties props = new Properties(); props.put("otherParam.a", "123"); props.put("otherParam.b", "456"); props.put("otherParam.c", "789"); String str = PropertyParser.parse("123=${otherParam.a},456=${otherParam.c},789=${otherParam.b}", props);
- 自定义
//使用Properties public static String genericTokenParser(Properties properties, String str) { TokenHandler handler = new TokenHandler() { @Override public String handleToken(String content) { return (String) properties.get(content); } }; GenericTokenParser parser = new GenericTokenParser("${", "}", handler); return parser.parse(str); }
//使