Skip to content

Instantly share code, notes, and snippets.

@imikay
Last active January 23, 2022 14:16
Show Gist options
  • Save imikay/0f9f0d71e613848ee647cd4d543e3d49 to your computer and use it in GitHub Desktop.
Save imikay/0f9f0d71e613848ee647cd4d543e3d49 to your computer and use it in GitHub Desktop.
Pass array/list data to Spring with axios

That's one way to do this, on Spring side

@PostMapping("api/user")
public Response theAction(@RequestBody List<User> users)

on the javascript side,

      let data = JSON.stringify([{name: 'dddddd'}, {name: 'bbbbb'}]);

      axios.post("/user/update/social-accounts", data, {
          headers: {
            "Content-Type": "application/json", // very important
          },
        })
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment