导入(不需要进行配置,会自动配置,):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
@Autowired
private Configuration configuration;
@Test
public void test1() throws IOException, TemplateException {
//Template template = configuration.getTemplate("settlementPayment.ftl"); 默认获取resource/templates/ 下的ftl文件
//字符串注入(后台可配置,灵活)
String model = "你好 ${name}";
Template template = new Template("xx1abvc", model, configuration);
//除了获取Template方式不同,其他都一样
Map<String, String> map = Map.of("name", "李四");
StringWriter writer = new StringWriter();
template.process(map,writer);
System.out.println(template.getName());
System.out.println(writer.toString());
}
SpringBoot Template模版适用(可用于转换为PDF,DOC,HTML等)
最新推荐文章于 2024-07-06 14:47:53 发布