* BAEL-3010 changing template dir

* BAEL-3010 Add ThymeleafConfig
This commit is contained in:
Amy DeGregorio 2019-07-25 01:22:28 -04:00 committed by maibin
parent 4062ad667d
commit 2c53cdd44e
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.thymeleaf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
@Configuration
public class ThymeleafConfig {
@Bean
public ClassLoaderTemplateResolver secondaryTemplateResolver() {
ClassLoaderTemplateResolver secondaryTemplateResolver = new ClassLoaderTemplateResolver();
secondaryTemplateResolver.setPrefix("templates-2/");
secondaryTemplateResolver.setSuffix(".html");
secondaryTemplateResolver.setTemplateMode(TemplateMode.HTML);
secondaryTemplateResolver.setCharacterEncoding("UTF-8");
secondaryTemplateResolver.setOrder(1);
secondaryTemplateResolver.setCheckExistence(true);
return secondaryTemplateResolver;
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.thymeleaf.templatedir;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "hello";
}
}

View File

@ -0,0 +1 @@
#spring.thymeleaf.prefix=classpath:/templates-2/

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Enums in Thymeleaf</title>
</head>
<body>
<h2>Hello from 'templates/templates-2'</h2>
</body>
</html>