axios.post('/api/someUrl', {
name: 'John',
age: 30
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
后端部分:
@PostMapping("/api/someUrl")
public void someFunction(@RequestBody User user) {
// do something with user object
}
其中User对象中需要包含与前端传递的JSON对象属性名一致的属性,如下所示:
public class User {
private String name;
private int age;
// Getter and Setter methods
}