简体   繁体   English

春季在单桩方法中访问多个pojo

[英]Acessing multiple pojo in single post method in spring

I have three three different POJO files for my spring project. 我的春季项目有三个三个不同的POJO文件。 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. 当我从angular js(也来自不同的POJO类)页面发送数据到spring mvc时,我的spring post方法只使用一个POJO类。谁能告诉我如何在单个spring post方法中调用多个POJO类在下面的控制器中,clue,cluelvl和cluedesc来自clueData POJO类,ans来自clueAns POJO。仅告诉我如何在一个post方法内调用多个POJO。

@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. 您应该将ClueDataClueAns合并到一个POJO中。 Spring is trying to map whole request body to a parameter annotated with @RequestBody . Spring试图将整个请求主体映射到带有@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. @RequestBody方法参数注释指示方法参数应绑定到HTTP请求正文的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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