简体   繁体   中英

Acessing multiple pojo in single post method in spring

I have three three different POJO files for my spring project. When i am sending data from angular js(which is also coming from different POJO classes) page to spring mvc , my spring post method is taking only one POJO class .Can anyone tell me that how to call multiple POJO classes in single spring post method.In the following controller ,clue,cluelvl and cluedesc are from clueData POJO class and ans is from clueAns POJO .Just tell me how to call multiple POJO inside one post method.

@RequestMapping(value = "/saveAndSubmit", method = RequestMethod.POST)
    public @ResponseBody void save(@RequestBody ClueData clueData , ClueAns clueans)
            //,@RequestBody List<ClueTag> clueTagList) 
    {       System.out.println(" Inside saveAndSubmit method ");
            System.out.println("ans:-" +clueans.getAns() );
            System.out.println("clue:-" +clueData.getClue() );
            System.out.println("level:-" +clueData.getClueLvl() );
            System.out.println("clueDESC:-" +clueData.getClueDesc());
}

You should combine ClueData and ClueAns into a single POJO. Spring is trying to map whole request body to a parameter annotated with @RequestBody . From the Spring spec :

The @RequestBody method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM