전체 글

개발자 이우진의 기술 블로그입니다
https://stackoverflow.com/a/73478165/21138374 @EnableWebMvc showing date in array formateWe had two application on spring boot. One was spring rest api based & second was spring MVC based. We have megred both the application due to some business reasons as the context was the same ...stackoverflow.com@Configurationpublic class WebConfig implements WebMvcConfigurer { // 다른 코드 /** * HTTP..
문제점현실의 객체는 순환 참조 관계를 가질 수 있다. 그러나 이를 코드로 구현할 때 문제가 발생한다. 그래서 클래스 설계를 할 때 현실의 순환 참조 관계에 있는 클래스들을 프로그램에서는 순환 참조하지 않도록 설계해야 한다.예를 들어, RPG 게임의 캐릭터와 몬스터는 서로 공격하고 데미지를 주고 받을 수 있기 때문에 순환 참조 관계를 갖는 것처럼 보인다. 그러나 이를 구현할 때는 Battle이 Chracater와 Monster에 의존하게 하여 순환 참조를 피할 수 있다. 이것이 뒤에서 설명할 중재자 패턴이기도 하다.생성할 때의 문제: 서로 의존성을 주입받아야 하는 관계에 놓여 있기 때문에 어느 클래스도 생성할 수 없다.A를 생성하려면 B 인스턴스가 필요하고, B를 생성하려면 A 인스턴스가 필요한 관계이니 ..
https://docs.spring.io/spring-framework/reference/core/validation/convert.html Spring Type Conversion :: Spring FrameworkWhen you require a sophisticated Converter implementation, consider using the GenericConverter interface. With a more flexible but less strongly typed signature than Converter, a GenericConverter supports converting between multiple source and target typesdocs.spring.io
개요 @IterableMapping(qualifiedByName = "toDto(RunHabit)") List toDtoList(List runHabits);@IterableMapping을 이용하면 리스트를 매핑할 때 요소 하나를 매핑할 메소드를 지정할 수 있다. 객체 하나를 매핑할 때 사용한 메소드를 재사용하여 같은 규칙을 사용할 수 있는 장점이 있다. 설명@Mapper(componentModel = "spring", uses = {HabitAlertMapper.class})@Named("RunHabitMapper")public interface RunHabitMapper { RunHabitMapper INSTANCE = Mappers.getMapper(RunHabitMapper.cla..
· Java
배경자바는 모든 객체가 클래스의 인스턴스여야 한다. 그래서 타입스크립트의 객체 리터럴({ attr1, attr2 })나 파이썬의 튜플((val1, val2))처럼 단순히 객체 두 개를 저장해야 할 때도 클래스를 정의해야 한다. 이 점은 다른 언어에 비해 번거롭거 시간이 더 들 수 있다. 그래서 Java에서도 Tuple을 활용하기 위해 javatuples 라이브러리를 활용할 수 있다출처https://www.baeldung.com/java-tuples Introduction to Javatuples | BaeldungLearn how to use javatuples library that provides elegant semantics for working with tuples.www.baeldung.com
요약그렇다.getter도 메소드이기 때문이다응용하면 getter 메소드는 유지하면서 구현 클래스에서 멤버 값을 그대로 보내는 대신, 기존의 멤버로 계산된 값을 리턴하게 구현할 수 있다.사용 사례Java List의 `.size()`주의점 (의견)그래도 인터페이스는 공유해야할 행동을 정의하는 것이 더 좋기 때문에 interface에 멤버 값을 반환하는 getter를 남용하는 것은 지양하는 게 좋을 것 같다. 정말 그 기능을 구현하는 클래스가 공통적으로 특정 값을 반환할 필요가 있을 때만 선언하는 것이 좋을 것 같다. callee가 호출할 수 있도록.사실 찾아본 목적은 DTO에서 특정 필드를 재사용하기 위해서였다. 이 경우, Spring framework은 사실 getter와 setter라는 public 메..
요약Spring Web은 HTTP Request Parameter(?property=vale)를 개발자가 정의한 클래스 객체로 바인딩하기 위해서 생성자, getter, setter 메소드를 호출한다배경Request Param 클래스를 만들다가 페이지네이션을 할 때 쓰는 속성 page와 size를 인터페이스화 해서 api에서 공통으로 관리하면 좋겠다는 생각을 했다./** * 목록 조회 API - 페이지네이션 기능을 사용할 때 쓰는 Request Param 속성. */public interface PaginationRequestParam { /** * 페이지 번호 */ Integer getPage(); /** * 페이지 당 데이터 수 */ Integer ge..
요약String -> Enum converter 인터페이스를 구현하고 추가한다enum class에는 String -> Enum 형태의 팩토리 메서드를 추가한다 (.of()) 출처https://www.baeldung.com/spring-enum-request-param Using Enums as Request Parameters in Spring | BaeldungLearn how to use enums as request parameters in Spring REST controllers and how to handle exceptions triggered by invalid input.www.baeldung.com