@PostMapping("/add") public String addItemV4(@ModelAttribute Item item, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { //주의할 점은 BindingResult는 @ModelAttribute를 붙인 오브젝트 뒤에 오는 것으로 순서가 중요하다. //필드 검증 log.info("objectName = {}", bindingResult.getObjectName()); log.info("object = {}", bindingResult.getTarget()); //item.toString 사용 // 로그를 돌려보면 //objectName = item //o..
//필드 검증 if(StringUtils.isEmpty(item.getItemName())){ bindingResult.addError(new FieldError("item","itemName", item.getItemName(), false , null, null, "상품명을 입력해주세요.")); //3번의 field값을 넣으면 오류가 발생했을 때에 오류값을 html에서 표시해 줄 수 있게 모델에 넣어준다. 필드의 타입이 Integer인데 문자열이 들어가도 넣어준다. 그 이유는 item에 넣기 이전에 아닌 리퀘스트에서 넣어준다고 생각하면 된다. //bindingResult.addError(new FieldError("item","itemName","상품명을 입력해주세요.")); } if(item.get..
@PostMapping("/add") public String addItem(@ModelAttribute Item item, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { //주의할 점은 BindingResult는 @ModelAttribute를 붙인 오브젝트 뒤에 오는 것으로 순서가 중요하다. //필드 검증 if(StringUtils.isEmpty(item.getItemName())){ bindingResult.addError(new FieldError("item","itemName","상품명을 입력해주세요.")); } if(item.getPrice() == null || item.getPrice() =..
- Total
- Today
- Yesterday
- reject
- jpa api
- 백엔드 개발자 공부
- Java
- JPA
- 예외처리
- 리터럴
- ArgumentResolver
- filter
- 스프링부트
- 로그인
- SpringBoot
- 인터셉터
- Intercepter
- 컨트
- React
- react실행
- BindingResult
- 항해99
- 백엔드 개발자 역량
- 향해플러스
- 항해플러스
- 향해99
- HTTP
- thymleaf
- hypertexttransferprotocol
- 향해플러스백엔드
- 스프링공부
- rejectValue
- exception
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |