我有这么@Controller:
@Controller
public class CandidateMenuController{
@ModelAttribute(value = "vacancies")
public Set<Vacancy> loadVacancies() {
return vacancyService.getAll();
}
@ModelAttribute(value = "vacanciesForCandidate")
public Set<Vacancy> vacanciesForCandidate(@RequestParam(required = false) List<Integer> vacanciesSelected,
@ModelAttribute("vacancies")Set<Vacancy> allVacancies ) {
.....
}
}
有时效果很好,但有时我看到异常:
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.Set]: Specified class is an interface
显然,这取决于 @ModelAttrributes 方法调用的顺序。
我知道我可以手动在 @ModelAttribute 方法中手动调用必要的方法,但是如何管理 @ModelAttribute 方法调用?