oolongsawel / springboot_study

springboot_study
0 stars 0 forks source link

주문 테이블 생성 및 주문등록 기능 추가 #11

Open oolongsawel opened 2 years ago

oolongsawel commented 2 years ago

주문정보 데이터가 들어가는 테이블 생성


create table orders
(
order_id bigint generated by default as identity,
member_id  bigint , 
member_name varchar(255) NOT NULL,
memo varchar(255),
total_count bigint ,
price bigint ,
order_date date default sysdate,
pick_up_date date,
pick_up_yn boolean default  '0',
primary key (order_id ) ,
-- FOREIGN KEY (member_id) REFERENCES member (id) 임시뺌
);
oolongsawel commented 1 year ago

에러로그

2022-09-25 22:55:29.185  WARN 7624 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved
 [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult:
 2 errors<EOL>Field error in object 'ordersForm' on field 'orderDate': rejected value [2022-09-26]; codes 
[typeMismatch.ordersForm.orderDate,typeMismatch.orderDate,typeMismatch.java.util.Date,typeMismatch]; arguments 
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [ordersForm.orderDate,orderDate]; arguments 
[]; default message [orderDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 
'java.util.Date' for property 'orderDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed
 to convert from type [java.lang.String] to type [java.util.Date] for value '2022-09-26'; nested exception is 
java.lang.IllegalArgumentException]<EOL>Field error in object 'ordersForm' on field 'pickUpDate': rejected value [2022-09-25]; 
codes [typeMismatch.ordersForm.pickUpDate,typeMismatch.pickUpDate,typeMismatch.java.util.Date,typeMismatch]; arguments
 [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ordersForm.pickUpDate,pickUpDate]; 
arguments []; default message [pickUpDate]]; default message [Failed to convert property value of type 'java.lang.String' to 
required type 'java.util.Date' for property 'pickUpDate'; nested exception is 
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type 
[java.util.Date] for value '2022-09-25'; nested exception is java.lang.IllegalArgumentException]]

참고 : Spring MVC 에서 Date 타입의 파라미터 처리 https://www.hungrydiver.co.kr/bbs/detail/develop?id=73

AS-IS

@Getter
@Setter
@ToString
public class OrdersForm {

    private Date  orderDate; //주문날짜

    private Date pickUpDate; //찾은날짜

}

TO-BE

@Getter
@Setter
@ToString
public class OrdersForm {

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date  orderDate; //주문날짜

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date pickUpDate; //찾은날짜

}