Problems sending multiple objects through POST and SPRING-MVC

前端 未结 3 1053
一整个雨季
一整个雨季 2021-01-05 04:43

I\'m developing REST services which have to receive multiple info. In this case, two objects and an attribute.

This is the javascript where I\'m testing the POST req

3条回答
  •  太阳男子
    2021-01-05 05:13

    You can create a java bean(POJO) containing all the objects like..

    class JavaBean{
        private User user;
        private UserTOSubscribe  userToSubscribe;
        private Long openId;
    
        // getter and setter
    }
    

    and pass this bean in to the Web service. so web service looks like..

    @RequestMapping(method=RequestMethod.POST, value="/subscribeUser.json")
    public @ResponseBody Message subscribeUser(@RequestBody JavaBean javaBean) {
        ...
    }
    

提交回复
热议问题