public interface UserProfile {
String getUsername();
String getProfileImageUrl();
}
// select username, profileImageUrl from user; // closed projection
@Value(SpEL)
을 사용해서 연산을 할 수 있다.예시
public interface UserProfile {
String getUsername();
String getProfileImageUrl();
@Value("#{target.profileImageUrl != null}")
boolean hasProfileImage();
default String getUserInfo() {
return getUsername() + " " + (hasProfileImage() ? getProfileImageUrl() : "");
}
}
예시
@Getter
@AllArgsConstructor
public class UserInfo {
private String username;
private String password;
public String getUserInfo() {
return username + " " + password;
}
}
예시
// UserRepository.java
<T> List<T> findByProfileImageUrlStartingWith(String profileImageUrlStartWith, Class<T> type);