FrontEnd/Thymeleaf
커스텀 함수 사용(with Spring)
lovineff
2021. 3. 9. 17:07
Custom으로 등록할 클래스 생성
@Slf4j
public class CustomThymeleaf {
...
}
Dialect를 이용하여 클래스 사용 등록
@Component
public class CustomThymeleafDialect extends AbstractDialect implements IExpressionObjectDialect {
protected CustomThymeleafDialect() {
super("CustomThymeleafDialect");
}
@Override
public IExpressionObjectFactory getExpressionObjectFactory() {
return new IExpressionObjectFactory() {
@Override
public Set<String> getAllExpressionObjectNames() {
return Collections.singleton("customThymeleaf");
}
@Override
public Object buildObject(IExpressionContext context, String expressionObjectName) {
return new CustomThymeleaf();
}
@Override
public boolean isCacheable(String expressionObjectName) {
return true;
}
};
}
}
HTML 호출부
<td th:text="${#customThymeleaf.toStrToDate(disclosureModel.establishedDate, '.')}"></td>