是什么导致“java.lang.IllegalStateException:BindingResult或bean名称的普通目标对象‘命令’作为请求属性可用”?
public class Application extends AbstractAnnotationConfigDispatcherServletInitializer { protected Class<?>[] getRootConfigClasses() { return new Class<?>[] {}; } protected Class<?>[] getServletConfigClasses() { return new Class<?>[] { SpringServletConfig.class }; } protected String[] getServletMappings() { return new String[] { "/" }; }}
@Configuration@ComponentScan("com.example")public class SpringServletConfig extends WebMvcConfigurationSupport { @Bean public InternalResourceViewResolver resolver() { InternalResourceViewResolver vr = new InternalResourceViewResolver(); vr.setPrefix("WEB-INF/jsps/"); vr.setSuffix(".jsp"); return vr; }}
@Controller
com.example
@Controllerpublic class MovieController { private final CopyOnWriteArrayList<Movie> movies = new CopyOnWriteArrayList<>(); @RequestMapping(path = "/movies", method = RequestMethod.GET) public String homePage(Model model) { model.addAttribute("movies", movies); return "index"; } @RequestMapping(path = "/movies", method = RequestMethod.POST) public String upload(@ModelAttribute("movie") Movie movie, BindingResult errors) { if (!errors.hasErrors()) { movies.add(movie); } return "redirect:/movies"; } public static class Movie { private String filmName; public String getFilmName() { return filmName; } public void setFilmName(String filmName) { this.filmName = filmName; } }}
/Example
http://localhost:8080/Example/movies
<form>
Movie
Movie
<form:form>
繁花不似锦
ibeautiful