Conversation
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| AnimalDTO animalDTO = (AnimalDTO) o; | ||
| return animalId == animalDTO.animalId; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(animalId); | ||
| } |
There was a problem hiding this comment.
equals & hashcode를 재정의하신 이유가 있을까요?
There was a problem hiding this comment.
사용자의 여러 키워드에 대해서 매칭된 동물DTO 집합을 만들 때, 중복되는 동물은 추가하지 않아야해서 equals()와 hashCode() 를 재정의했습니다.
| @Setter | ||
| public class CreateAccessTokenRequest { | ||
| private String refreshToken; | ||
| } No newline at end of file |
There was a problem hiding this comment.
| @Getter | ||
| @Setter | ||
| @Component | ||
| @ConfigurationProperties("jwt") |
There was a problem hiding this comment.
@ConfigurationProperties("jwt")를 활용하여 property를 묶어서 관리했군요 👍
| import java.util.Date; | ||
| import java.util.Set; | ||
|
|
||
| @Service |
There was a problem hiding this comment.
Service 어노테이션을 선택한 이유가 있을까요?
Component와 Service는 어떤 차이가 있을까요
There was a problem hiding this comment.
처음엔 tokenProvider도 토큰을 생성하는 동작을 하니까 비즈니스 로직의 일종이라고 생각하고 사용했습니다.
둘 다 기능적으로는 차이가 없지만 @component는 Bean 클래스임을, @service는 비교적 복잡하고 특정한 기능을 하는 클래스임을 명시하기 위해 사용합니다. 알아보고 나니 @component가 더 적절한 것 같아서 수정했습니다.
| .formLogin(formLogin -> | ||
| formLogin | ||
| .loginPage("/login") | ||
| .defaultSuccessUrl("/home", true) | ||
| .permitAll() | ||
| )// 폼 기반 로그인 설정 | ||
| .logout(logoutConfig -> | ||
| logoutConfig | ||
| .logoutSuccessUrl("/login") | ||
| .invalidateHttpSession(true) | ||
| .permitAll() | ||
| ) |
There was a problem hiding this comment.
원래 html과 폼로그인 방식으로 구현하려고 했다가 JWT로 넘어가면서 삭제했습니다!
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Getter | ||
| @Setter |
There was a problem hiding this comment.
시간이 된다면 Setter를 제거해보시는것을 추천드립니다.
조금 길지만 Setter를 왜 지양해야하는지 설명하는 자세한 글이 있어 공유드립니다.
velog - setter 쓰지 말라고만 하고 가버리면 어떡해요
| @Builder // SQL 파라미터에 값을 쉽게 넣어주기 위함 | ||
| @Entity(name = "keywords") // 해당 class에서 사용할 테이블 명 | ||
| @AllArgsConstructor // 매개변수에 대한 생성자들을 자동 생성 | ||
| @NoArgsConstructor // 기본생성자를 자동 생성 |
There was a problem hiding this comment.
Entity를 선언하는 과정에서는 기본 생성자를 필수료 요구합니다.
Entity에 기본 생성자가 왜 필요할까요? 한번 생각해보면 좋을 것 같아 남겨봅니다
There was a problem hiding this comment.
JPA는 Entity의 기본 생성자로 객체를 먼저 생성한 뒤, Reflection API를 이용해 값을 넣기 때문에 기본 생성자가 필수입니다. 그리고 지연 로딩을 위해 프록시 객체를 사용하기 때문에 private 생성자는 사용하면 안됩니다.
| public RefreshToken update(String newRefreshToken){ | ||
| this.refreshToken = newRefreshToken; | ||
| return this; | ||
| } |
There was a problem hiding this comment.
객체의 상태가 업데이트 되었는데 굳이 this를 반환할 이유가 있을까요?
| <form action="/login/proc" method="POST"> | ||
| <input type="hidden" th:name="${_csrf?.parameterName}" th:value="${_csrf?.token}" /> | ||
| <div class="mb-3"> | ||
| <label class="form-label text-white">Email address</label> | ||
| <input type="userId" class="form-control" name="userId"> | ||
| </div> | ||
| <div class="mb-3"> | ||
| <label class="form-label text-white">Password</label> | ||
| <input type="password" class="form-control" name="password"> | ||
| </div> | ||
| <button type="submit" class="btn btn-primary">Submit</button> | ||
| </form> |
There was a problem hiding this comment.
로그인 폼을 만들어주셨네요~ 아마 SpringSecurity를 활용하며 생긴 양식같은데 잘 활용해보시길 바랍니다 🔥
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| @SpringBootTest | ||
| class TokenProviderTest { |

No description provided.