请求正文:
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;
}
}
答案 0 :(得分:-1)
您对ActiveJDBC API的使用不正确。
private void SignInUser()
{
... Code
await HttpContext.Authentication.SignInAsync(..);
}
set
- 您正在将对象的数据设置为同一个对象????? 您的模型需要(完整):
userInfo.set(userInfo.getUsername());
这就是你所需要的。
如果您需要在模型上设置值,您可以:
public class UserInfo extends Model {}
等。
我建议您阅读文档并尝试自行解决问题,因为您的问题显示您缺乏努力。