Thymeleaf Neither BindingResult nor plain target object for bean name 'person' available as request attribute

后端 未结 3 949
再見小時候
再見小時候 2021-01-01 01:08

From what I can tell this is set up correctly but I am getting the following error:

java.lang.IllegalStateException: Neither BindingResult nor plain target 
         


        
3条回答
  •  隐瞒了意图╮
    2021-01-01 01:11

    First I had the form in index.html

     @RequestMapping(value = "/", method = RequestMethod.GET)
        public String indexPage(){
            return "index";
        }
    

    So when my form:

    Was looking for / it was hitting the above method, NOT:

    @RequestMapping(value="/", method=RequestMethod.GET)
        public String contactForm(@Valid @ModelAttribute("person") Person person, BindingResult bindingResult,
                                  HttpServletRequest request, Model model) throws IOException {
    
            if(bindingResult.hasErrors()){
                System.out.println("There was a error "+bindingResult);
    
                return "index";
            }
    
            model.addAttribute("person", new Person());
            return "index";
        }
    

    Which was correct!

    I had to remove the first method and it worked.

提交回复
热议问题