Java字符串替换功能

(1):替换字符串中${name} 类似的字符串 比如:

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;

import freemarker.template.Configuration;
import freemarker.template.Template;```

String templateString= "有一个名字叫${name},是个牛皮人物";
model.put("name","张三");
public static String renderString(String templateString, Map model) {
		try {
			StringWriter result = new StringWriter();
			Template t = new Template("name", new StringReader(templateString), new Configuration());
			t.process(model, result);
			return result.toString();
		} catch (Exception e) {
			throw Exceptions.unchecked(e);
		}
	}

(2):后续更新

你可能感兴趣的:(String)