I have a javascript variable which is an array of MyObjects. I can display this variable to the view with the following code:
{{ user.firstName }}{{ user.lastName }}Now I am trying to send this array to the server. I am trying something like:
lala.send = function() {
$http({
method: 'GET',
url: "http://localhost:8080/server/" + lala.users
}).then(function successCallback(response) {
if (response.status == 200) {
lala.users = response.data
}
});
};
How can I pass this array to a list on the server side? Till now I have something like this.
@RequestMapping(value = "/server/{users}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> transform(@PathVariable("users") String[] users) {
List results2 = new ArrayList<>();
//pass array to a list??
return new ResponseEntity<>(results2, HttpStatus.OK);
}
解决方案
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.