Java

    [JPA] 패턴, 준영속 엔티티

    📄 도메인 모델 패턴 엔티티 안에 비즈니스 로직이 포함된 패턴 객체지향을 활용하는 기법 📄 트랜잭션 스크립트 패턴 서비스 계층에서 모든 비즈니스 로직을 처리하는 패턴 [디자인패턴] Domain Model Pattern vs Transaction Script Pattern Domain Model Pattern [도메인 모델 패턴]이란? 대부분의 비즈니스 로직이 엔티티 안에 구성되어있습니다. 서비스 계층은 엔티티에 필요한 역할을 위임하는 역할을 합니다. 엔티티 안에 비즈니스 로직 applepick.tistory.com 📄 준영속 엔티티 영속성 컨텍스트가 더 이상 관리하지 않는 엔티티 임의로 만든 엔티티도 식별자를 갖고 있다면 준영속 엔티티로 볼 수 있다. 준영속 엔티티를 수정하는 방법 1. 영속 엔티티를 가..

    [JPA] 엔티티 설계시 주의점

    📄 값 타입은 변경 불가능하게 설계한다. @Embeddable @Getter @AllArgsConstructor public class Address { private String city; private String street; private String zipcode; protected Address() { } } Setter를 제거해 변경 불가능하게 만든다. JPA 스펙상 임베디드 타입은 public 또는 protected인 빈 생성자가 필요하다. 그나마 안전한 protected 제어자를 사용한다. 📄 가급적 Setter를 사용하지 않는다. Setter를 사용하면 변경 포인트가 많아 유지보수가 어려워진다. 📄 모든 연관관계는 지연 로딩으로 설정한다. 즉시 로딩 FetchType.EAGER는 예측과..

    [Java] Convert Char to Int, Int to Char

    Char to Int public class Main { public static void main(String[] args) { char c = '1'; int num1, num2; num1 = Character.getNumericValue(c); num2 = c - '0'; // 자동 형변환, 아스키 코드 (int)c - int('0') == 49 - 48 == 1 System.out.println(num1); System.out.println(num2); } } // 출력 1 1 Int to Char public class Main { public static void main(String[] args) { int num = 1; char c1, c2; c1 = Character.forDigit(n..

    [Java] 객체 정렬하기 (링크)

    [Java] 객체 정렬하기 1부 - Comparable vs Comparator Engineering Blog by Dale Seo www.daleseo.com

    [Java] System.in.read() (링크)

    [Java] System.in.read() - 1 알고리즘 문제를 풀다 보면 한 문자를 입력받고 바로 처리해주어야 할 때가 있다. 보통 BufferedReader c... blog.naver.com [Java] System.in.read() - 2 이제 FileInputStream class를 살펴보자. 봐야 한다. BufferedInputStream 내부에서 FileInputStr... blog.naver.com

    [Java] Stream

    배열에 있는 값을 짝수만 중복을 제거해 역순으로 출력하는 코드 import java.util.*; public class Exam { public static void main(String[] args) { int[] arr = {5, 4, 3, 2, 1, 1, 2, 3, 4, 5}; ArrayList list = new ArrayList(); for(int i=0; i

    [Spring] 정적 컨텐츠, MVC와 템플릿 엔진, API

    정적 컨텐츠 - html 파일을 그대로 불러와 웹페이지에 표시 MVC와 템플릿 엔진 - 템플릿 엔진을 모델, 뷰, 컨트롤러 방식으로 나누어 뷰를 템플릿 엔진으로 html을 렌더링해 웹페이지에 표시 // hello-spring/src/main/java/hello/hellospring/controller/HelloController.java package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframewo..

    [Java] java.time 패키지

    Java SE 8부터 지원하는 새롭게 재 디자인한 패키지 import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; LocalDateTime timePoint = LocalDateTime.now(); LocalDate ld = LocalDate.of(2022, Month.MAY, 10); LocalTime lt1 = LocalTime.of(15, 50); LocalTime lt2 = LocalTime.parse("13:10:30"); System.out.println(timePoint); System.out.println(ld); System.out.println(..