Browse Source

打包模板

zhangheng 3 years ago
parent
commit
9f83e47890
1 changed files with 13 additions and 1 deletions
  1. 13 1
      server/src/main/java/edp/davinci/core/config/ThymeleafConfig.java

+ 13 - 1
server/src/main/java/edp/davinci/core/config/ThymeleafConfig.java

@@ -22,11 +22,14 @@ package edp.davinci.core.config;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.util.ResourceUtils;
 import org.thymeleaf.spring5.SpringTemplateEngine;
 import org.thymeleaf.templatemode.TemplateMode;
 import org.thymeleaf.templateresolver.FileTemplateResolver;
 
 import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.FileNotFoundException;
 
 @Configuration
 public class ThymeleafConfig {
@@ -41,8 +44,17 @@ public class ThymeleafConfig {
 
     @PostConstruct
     public void webResourcesResolver() {
+
+        File path = null;
+        try {
+             path = new File(ResourceUtils.getFile("classpath:").getPath());
+
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+        System.out.println(">>>>>" + path);
         FileTemplateResolver resolver = new FileTemplateResolver();
-        resolver.setPrefix("/templates/");
+        resolver.setPrefix("./templates/");
         resolver.setSuffix(".html");
         resolver.setTemplateMode(TemplateMode.HTML);
         resolver.setCharacterEncoding("UTF-8");