
라이브러리 추가
스프링부트 버전과 동일한 머스테치 라이브러리 의존성을 등록해준다.
implementation 'org.springframework.boot:spring-boot-starter-mustache:2.7.5'
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mustache/2.7.5
설정파일 생성
현재 머스테치는 .mustache 파일을 인식하게 되어있다.
머스테치가 .html 파일을 인식할 수 있도록 별도의 설정파일을 만들어준다.
package com.example.mustache.config;
import org.springframework.boot.web.servlet.view.MustacheViewResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MustacheConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
MustacheViewResolver resolver = new MustacheViewResolver();
resolver.setCharset("UTF-8");
resolver.setContentType("text/html; charset=UTF-8");
resolver.setPrefix("classpath:/templates/");
resolver.setSuffix(".html");
registry.viewResolver(resolver);
}
}
WebMvcConfigurer를 impl해서 위 메서드를 구현해주면 된다.
UTF-8, html, 경로 등을 설정해주면 이제 머스테치 템플렛이 .html파일을 인식할 수 있다.
'스프링' 카테고리의 다른 글
[스프링] Optional [orElse vs orElseGet] (0) | 2022.11.19 |
---|---|
[자바] Lombok - 부모클래스의 toString 호출하기 (0) | 2022.11.17 |
[스프링] Querydsl - 동적쿼리 구현 방법 (0) | 2022.10.19 |
[스프링] @RestControllerAdvice 이용한 예외처리 방법 (0) | 2022.10.14 |
[스프링] 톰캣(Tomcat) 서버 시작 속도 개선 (2) | 2022.10.06 |