Thymeleaf : http://www.thymeleaf.org
Thymeleaf Spring mail 샘플 : http://www.thymeleaf.org/springmail.html
Thymeleaf 태그 설명 : http://www.thymeleaf.org/standarddialect5minutes.html
git : https://github.com/thymeleaf
Thymeleaf Tiles 결합 : https://github.com/thymeleaf/thymeleaf-extras-tiles2
[참고]
james 메일 보내기 : http://tyboss.tistory.com/entry/Java-James-서버-사용하여-메일mail-보내기
Inputstream 사용 : https://stackoverflow.com/questions/53323313/java-thymeleaf-how-to-process-an-inputstream-in-templateengine-stand-alon
1. Maven으로 Thymeleaf Library 추가하기
<dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>2.0.16</version> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring3</artifactId> <version>2.0.16</version> </dependency> |
2. Spring에 Thymeleaf 설정하기
<bean id="emailTemplateResolver" class="org.thymeleaf.templateresolver.ClassLoaderTemplateResolver"> |
3. Template 만들기
다음에서 설명하겠지만 Context.setVariable(key, value) 로 변수값을 설정 후에 아래 빨간색 부분처럼 사용할 수 있다. 일반 텍스트는 th:text="${key}" 로 사용하고 URL은 th:href="@{${key}}" 로 사용한다.
- template.html
<!DOCTYPE html> |
4. Controller에서 Template 불러오기
4-1. ClassLoaderTemplateResolver 사용시
@RequestMapping("mail.do") |
4-2. ServletContextTemplateResolver 사용시
@Autowired |
4-3. StringTemplateResolver 사용시
StringTemplateResolver templateResolver = new StringTemplateResolver(); |