原因:
tomcat启动和jar包启动加载的位置不同!
解决办法
cfg.setDirectoryForTemplateLoading(new File(“src/main/resources/templates”));
修改为
cfg.setClassForTemplateLoading(this.getClass(),“/templates”);
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/>
</parent>