아래와 같은 에러를 만났다.
An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments
원인은
Valid 를 사용할 경우 Error 나 BindingResult 를 잡을수가 있는데,
Valid 바로 다음에 Errors 나 BindingResult 가 나와야한다.
Valid 관련해서는 아래 참고 포스팅 참고 바란다.
두 코드를 보면 올바른 코드와 잘못된 코드를 확인 가능하다.
(스택오버플로우 사이트 참고)
올바른 코드 | @RequestMapping(value = "/catowners", method = RequestMethod.GET) public String findOwnersOfPetType(Integer typeID, BindingResult result, Map<String, Object> model) { |
잘못된 코드 | @RequestMapping(value = "/catowners", method = RequestMethod.GET) public String findOwnersOfPetType(@Valid Integer typeID, BindingResult result, Map<String, Object> model) |
An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @Requ
I am teaching myself Spring by dissecting example applications and then adding code here and there to test theories that I develop during the dissection. I am getting the following error message w...
stackoverflow.com
참고 포스팅
https://thenicesj.tistory.com/305
@Valid annotation (BindingResult, Error)(유효성 검사)
지난번에 다뤘던 포스팅 중에서 not null관련 포스팅도 존재하고, jackson 관련 포스팅도 존재한다. 둘의 공통점은 dto 등에서 변수에 설정을 걸어주는것이다. 하지만 이 둘 말고도 또다른 annotation이
thenicesj.tistory.com
'IT > Java' 카테고리의 다른 글
CSV 파일읽어서 Repository 설정 방법 (8) | 2024.08.21 |
---|---|
@Valid 를 Dto 에 적용하기 (7) | 2024.08.18 |
ConcurrentHashMap 을 활용한 동시성 제어 (10) | 2024.08.16 |
ThreadPool Default (21) | 2024.08.15 |
자바에서 Thread 확인 (6) | 2024.08.14 |
댓글