@Test voidtest(){ // setter 사용 User u1 = new User(); u1.setName("마리아"); u1.setEmail("maria@example.com"); u1.setCreatedAt(LocalDateTime.now()); u1.setUpdatedAt(LocalDateTime.now()); System.out.println("@ test u1: "+u1); // @AllArgsConstructor 생성자로 생성 User u2 = new User("가나다", "ganada@example.com", LocalDateTime.now(), LocalDateTime.now()); System.out.println("@ test u2: "+u2); // @NoArgsConstructor 생성자로 생성 User u3 = new User(); System.out.println("@ test u3: "+u3); // @Builder 로 생성 User u4 = User.builder() .name("마바사") .email("mabasa") .updatedAt(LocalDateTime.now()) .build(); System.out.println("@ test u4: "+u4); }
}
User객체 4개가 생성되었고 그 결과는 아래와 같다.
1 2 3 4
@ test u1: User(name=마리아, email=maria@example.com, createdAt=2021-08-18T22:01:39.588614800, updatedAt=2021-08-18T22:01:39.588614800) @ test u2: User(name=가나다, email=ganada@example.com, createdAt=2021-08-18T22:01:39.588614800, updatedAt=2021-08-18T22:01:39.588614800) @ test u3: User(name=null, email=null, createdAt=2021-08-18T22:01:39.588614800, updatedAt=null) @ test u4: User(name=마바사, email=mabasa, createdAt=null, updatedAt=2021-08-18T22:01:39.589613600)