티스토리 뷰

728x90
반응형

Spring Boot에서 템플릿 엔진으로 mustache를 사용할 때 

key 값이 없으면 에러가 발생되는데 MustacheEnvironmentCollector로 default value 값을 설정할 수 있었다.

@Bean
public Mustache.Compiler mustacheCompiler(
  Mustache.TemplateLoader templateLoader, 
  Environment environment) {

    MustacheEnvironmentCollector collector
      = new MustacheEnvironmentCollector();
    collector.setEnvironment(environment);

    return Mustache.compiler()
      .defaultValue("Some Default Value")
      .withLoader(templateLoader)
      .withCollector(collector);
}

 

하지만 Spring boot 2.7 이후부터 MustacheEnvironmentCollector가 deprecated 되었고

MustacheEnvironmentCollector를 제거하면 

@Bean
public Mustache.Compiler mustacheCompiler(
  Mustache.TemplateLoader templateLoader, 
  Environment environment) {

    return Mustache.compiler()
      .defaultValue("Some Default Value")
      .withLoader(templateLoader);
}

 

mustache로 랜딩된 데이터 중에 한글이 ??? 으로 깨지는 현상이 있다.

application.yml 에 아래 설정 추가

server.servlet.encoding.force-response: true

 

 

https://www.baeldung.com/spring-boot-mustache

https://mkyong.com/spring-boot/spring-boot-and-mustache-default-value/

728x90
반응형
반응형
300x250