[Springboot RestAPI] 1. 스토어 앱 DTO 문제 정의

손영민's avatar
Aug 26, 2025
[Springboot RestAPI] 1. 스토어 앱 DTO 문제 정의
 
notion image
자바 프로젝트로 stapp에 gradle로 생성
 
 
 
 
 
 
 
mvn repository에 lombok 에 들어가서
notion image
 
dependencies { // https://mvnrepository.com/artifact/org.projectlombok/lombok compileOnly("org.projectlombok:lombok:1.18.38") testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' }
붙여넣기하고 코끼리 모양클릭
 
App1.java
package ex01; import java.util.Arrays; import java.util.List; public class App1 { public static void main(String[] args) { // 판매자 로직!!!!!!!!! // 1. 상품 2개 Product p1 = new Product(1, "바지"); Product p2 = new Product(2, "티"); List<Product> products = Arrays.asList(p1, p2); // 1번 문제 -> products DTO로 옮기기 // 2. 상품 옵션 4개 생성 ProductOption op1 = new ProductOption(1, "파란바지", 1000, 10, p1); ProductOption op2 = new ProductOption(2, "빨간바지", 2000, 10, p1); ProductOption op3 = new ProductOption(3, "노랑티", 1000, 10, p2); ProductOption op4 = new ProductOption(4, "하얀티", 2000, 10, p2); List<ProductOption> p1Options = Arrays.asList(op1, op2); List<ProductOption> p2Options = Arrays.asList(op3, op4); // 2번 문제 -> p2, p2Options -> ProductDetailDTO 로 옮기기 //구매자 로직!!!!!!!!!!! //3. 구매 Order or1 = new Order(1); OrderOption orOption1 = new OrderOption(1, "파란바지", 2, 2000, p1, or1); OrderOption orOption2 = new OrderOption(2, "빨간바지", 2, 4000, p1, or1); OrderOption orOption3 = new OrderOption(3, "하얀티", 5, 10000, p2, or1); op1.setQty(op1.getQty() - 2); op2.setQty(op2.getQty() - 2); op4.setQty(op4.getQty() - 5); Order or2 = new Order(2); OrderOption orOption4 = new OrderOption(4, "노랑티", 7, 7000, p2, or2); op3.setQty(op3.getQty() - 7); // 1번 문제 : 상품 목록 화면 // List<Product> -> List<ProductDTO> // 2번 문제 : 상품 상세 화면 (p2) // Product(p2, p2Options) -> ProductDetail // 3번 문제 : 주문 확인 상세 화면 (or2) // 틀렸음 : TempDTO 담기 // 4번 문제 : 주문 확인 상세 화면 (or1) // (orOption1, orOption2), (orOption3) -> OrderDetailDTO } }
 
Order.java
package ex01; import lombok.Builder; import lombok.Data; // 주문 @Data public class Order { private int id; @Builder public Order(int id) { this.id = id; } }
 
OrderOption.java
package ex01; import lombok.Builder; import lombok.Data; //주문 옵션(바지xl, 티L) @Data public class OrderOption { private int id; private String optionName; // 하얀티 private int qty; // 5개 private int totalPrice; // 10000원 private Product product; private Order order; @Builder public OrderOption(int id, String optionName, int qty, int totalPrice, Product product, Order order) { this.id = id; this.optionName = optionName; this.qty = qty; this.totalPrice = totalPrice; this.product = product; this.order = order; } }
 
Product.java
package ex01; import lombok.Builder; import lombok.Data; @Data public class Product { private int id; private String name; // 바지 @Builder public Product(int id, String name) { this.id = id; this.name = name; } }
 
ProductionOption
package ex01; import lombok.Builder; import lombok.Data; @Data public class ProductOption { private int id; private String name; private int price; private int qty; private Product product; @Builder public ProductOption(int id, String name, int price, int qty, Product product) { this.id = id; this.name = name; this.price = price; this.qty = qty; this.product = product; } public int getQty() { return qty; } public void setQty(int qty) { this.qty = qty; } }
 
1번 문제 : 상품 목록 화면 List<Product> -> List<ProductDTO>
notion image
 
 
// 2번 문제 : 상품 상세 화면 (p2) // Product(p2, p2Options) -> ProductDetail
notion image
 
 
// 3번 문제 : 주문 확인 상세 화면 (or2) // 틀렸음 : TempDTO 담기
notion image
 
 
// 4번 문제 : 주문 확인 상세 화면 (or1) // (orOption1, orOption2), (orOption3) -> OrderDetailDTO
notion image
Share article

sson17