zl程序教程

您现在的位置是:首页 >  其它

当前栏目

字符串占位符替换

字符串 替换 占位
2023-09-27 14:19:41 时间

 

  • Spring字符串占位符替换
import org.springframework.util.PropertyPlaceholderHelper;

import java.util.Properties;

public class PlaceholderUtil {
    private static PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
            "#{", "}", ":", false);

    public static String replacePlaceholders(String value, final Properties properties) {
       return helper.replacePlaceholders(value, properties);
    }

}
  •  String字符串替换(日期/数字等)
String time = String.format("%tc", date);
  • slfj  MessageFormatter
Object[] valueArr= {"aaa", 123};
MessageFormatter.arrayFormat("str {} int {}", valueArr).getMessage();

// {} 定位变量位置
// \{} 表示 跳过该对括号
// 前面再加 \ 则取消跳过