请求正文:
request.body {"username":"kkk.k999@gmail.com","userImage":"https://lh3.googleusercontent.com/-XdUIqdMkffA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50","role":"ROLE_USER","token":"ya29.GmIYBNhh5zs2Cpq1UI2iVzdxDvMVf2x8ggpEgM9Jvk51f5FOGodUZINrabY6K9Mhn6L82XpUhOyh5uIPhLZkAjIqS1hBu7un9QhMzRW35
RJM5ZwFozlBIuuxFRP4Y5xsTtdPGw"}
保存到 Db 时出错:
@Override
public void saveUserInfo(Request request) {
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/47seconds", "root", "admin");
ObjectMapper mapper = new ObjectMapper();
try {
UserInfo userInfo = mapper.readValue(request.body(), UserInfo.class);
userInfo.set(userInfo.getUsername());
userInfo.set(userInfo.getUserImage());
userInfo.set(userInfo.getRole());
userInfo.set(userInfo.getToken());
userInfo.saveIt();
} catch (IOException ex) {
Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
Base.close();
}
错误: java.lang.IllegalArgumentException:参数数量必须在 org.javalite.activejdbc.Model.set 处偶数
模型类和数据库中的参数数量匹配。数据库中的 id 是自动递增的,所以我没有从代码中传递它。
型号类:
@Table("user_info")
public class UserInfo extends Model {
private String username;
private String userImage;
private String token;
private String role;
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the userImage
*/
public String getUserImage() {
return userImage;
}
/**
* @param userImage the userImage to set
*/
public void setUserImage(String userImage) {
this.userImage = userImage;
}
/**
* @return the token
*/
public String getToken() {
return token;
}
/**
* @param token the token to set
*/
public void setToken(String token) {
this.token = token;
}
/**
* @return the role
*/
public String getRole() {
System.out.println("printing role "+ role);
return role;
}
/**
* @param role the role to set
*/
public void setRole(String role) {
this.role = role;
}
}