我想向我的REST API发出POST请求,但出现以下错误: REST API是在Spring中制作的 我有一个意外令牌:
POST请求呼叫:
http://localhost/users/load
Java代码:
@PostMapping(value = "/load")
public User load(@RequestBody final User user){
userRepository.save(user);
return userRepository.findByName(user.getName());
}
用户类别:
@Entity
public class User {
private Long id;
private String name;
private String username;
private String password;
@Id
@GeneratedValue
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getUsername(){
return username;
}
public void setUsername(String username){
this.username = username;
}
public String setPassword(){
return password;
}
public void getPassword(){
this.password = password;
}
}
JSON数据:
{
"name": "John",
"username": "randomUsername",
"password": "Password123!"
}
错误:
There was an error in evaluating the test script: SyntaxError: Unexpected token :
我希望该请求能够通过,但是没有通过