0

私は @Controller にとてもメソッドを持っています:

スキルリスト:

    @ModelAttribute(value = "skillsIdList")
        public Set<Skill> getSkillListById(@RequestParam(required = false) List<Integer> skills,@ModelAttribute("skills")List<Skill> allSkills ) {
            if (skills== null)
                return null;
            Set<Skill> returnList = new  HashSet<Skill>();
            for(Integer skillId:skills){
                for(Skill skill:allSkills){
                    if(skillId.equals(skill.getId())){
                        returnList.add(skill);
                        break;
                    }
                }   
            }
            return returnList;
        }

候補者:

@ModelAttribute(value = "candidateFromRequest")
    public Candidate loadCandidateById(@RequestParam(required = false) Integer idCandidate) {
        if (idCandidate!= null)
            return candidateService.findById(idCandidate);
        return null;
    }

空室:

@ModelAttribute(value = "vacanciesForCandidate")
    public Set<Vacancy> vacanciesForCandidate(@RequestParam(required = false) List<Integer> vacanciesSelected,@ModelAttribute("vacancies")List<Vacancy> allVacancies ) {
        if (vacanciesSelected== null)
            return null;
        Set<Vacancy> returnList = new  HashSet<Vacancy>();
        for(Integer vacancyId:vacanciesSelected){
            for(Vacancy vacancy:allVacancies){
                if(vacancyId.equals(vacancy.getId())){
                    returnList.add(vacancy);
                    break;
                }
            }   
        }
        return returnList;
    }

できます

@RequestMapping("/saveCandidate")
    public String saveCandidate(Model model,HttpServletRequest request,HttpResponse response
            ,@ModelAttribute("candidateFromRequest") Candidate candidateFromRequest
            ,@ModelAttribute("skillsIdList") Set<Skill> skills
           ,@ModelAttribute("vacanciesForCandidate") Set<Vacancy> vacanciesForCandidate
            )
    {
        candidateFromRequest.setSkills(skills);
        candidateFromRequest.setVacancies(vacanciesForCandidate);
        candidateService.update(candidateFromRequest);
        return "candidateMenu";
    }

しかし、それは機能しません (HTTP ステータス 400 - 必須の整数パラメーター 'idCandidate' が存在しません):

@RequestMapping("/addCandidate")
    public String addCandidate(Model model,HttpServletRequest request,HttpResponse response
            ,@ModelAttribute Candidate myCandidate
            ,@ModelAttribute("skillsIdList") Set<Skill> skills
           ,@ModelAttribute("vacanciesForCandidate") Set<Vacancy> vacanciesForCandidate)
    {
        myCandidate.setSkills(skills);
        myCandidate.setVacancies(vacanciesForCandidate);
        candidateService.add(myCandidate);
        return "candidateMenu";
    }

私は書いているので、このメッセージの原因がわかりません@RequestParam(required = false) Integer idCandidate

4

0 に答える 0