Skip to content Skip to sidebar Skip to footer

Send Array Of Objects Via Get Request With Angular's $http To Java Spring

I have a javascript variable which is an array of MyObjects. I can display this variable to the view with the following code:

Solution 1:

You can transform your string and use a delimiter, then parse it on your server side. You can also use HttpPost instead of HttpGet request so you can send JSON String and it is easier to parse.

Solution 2:

Based on Ranielle's answer I proceeded with HttpPost.

Here is the code:

lala.send = function() {
            $http.post("http://localhost:8080/server", lala.users ) 
            .then(functionsuccessCallback(response) {
                if (response.status == 200) {
                   lala.users = response.data
                }
            });
        };

And the Spring side

@RequestMapping(value ="server", method =RequestMethod.POST, produces =MediaType.APPLICATION_JSON_VALUE)
    publicResponseEntity<List<MyObjects> sort( @RequestBodyList<MyObjects> query) {
        List<MyObjects> results2 = new ArrayList<>();

        for(MyObjects a : query) {
                System.out.println(a.getFirstName());
        }

        return new ResponseEntity<>(results2, HttpStatus.OK);
    }

Post a Comment for "Send Array Of Objects Via Get Request With Angular's $http To Java Spring"