Attach
는 첨부파일 정보를 담은 클래스인데, image 여부를 굳이 변수에 담기보다 그냥 메소드 반환값으로 하면 다른 코드를 안 바꿔도 될 것 같아서 이미지 여부를 boolean으로 반환하는 메소드를 추가하였다.// Attach.java
// 이미지 여부 반환
public boolean isImage() {
String[] ext = {"jpg", "jpeg", "png", "gif"};
return Arrays.stream(ext).anyMatch(this.getATTF_EXE().toLowerCase()::equals);
}
Syntax :
<Class name>::<method name>
// stream의 모든 요소를 print
stream.forEach( System.out::println);
application.properties
에 작성하면서 한글로 주석을 달아놨었는데, github에 올라온 것을 보니 한글이 전부 깨져있는 것을 알게 되었다.window-preference
에서 설정하기thymeleaf-extras-java8time
를 이용해 간단히 포맷팅하는 방법이 있어서 적용해보았다.thymeleaf-extras-java8time
라이브러리 추가implementation 'org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.4.RELEASE'
thymeleaf-extras-java8time gradle
@Configuration
public class SpringConfig {
@Bean
public Java8TimeDialect java8TimeDialect() {
return new Java8TimeDialect();
}
...
}
<li th:each="post : ${postList}">
<span th:if="${post.POST_UPDATE==null}" th:text="|최초 작성일 : ${#temporals.format(post.POST_DATE, 'yyyy-MM-dd HH:mm')}|">최초 작성일</span>
<span th:unless="${post.POST_UPDATE==null}" th:text="|수정일 : ${#temporals.format(post.POST_UPDATE, 'yyyy-MM-dd HH:mm')}|">수정일</span>
</li>
org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method format(java.util.Date,java.lang.String) cannot be found on type org.thymeleaf.extras.java8time.expression.Temporals
LocalDateTime
으로 바꿔주고 나니 잘된다.// PostForm.java
// 게시물 최초 등록일
// String POST_DATE;
LocalDateTime POST_DATE;
// 게시물 수정일
// String POST_UPDATE;
LocalDateTime POST_UPDATE;