java.lang.IllegalArgumentException:参数数量必须在org.javalite.activejdbc.Model.set处为偶数 [英] java.lang.IllegalArgumentException: number of arguments must be even at org.javalite.activejdbc.Model.set

查看:192
本文介绍了java.lang.IllegalArgumentException:参数数量必须在org.javalite.activejdbc.Model.set处为偶数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求正文:

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:number参数的个数甚至必须在org.javalite.activejdbc.Model.set

Error: java.lang.IllegalArgumentException: number of arguments must be even at org.javalite.activejdbc.Model.set

在模型类和数据库中匹配的参数数目。数据库内部的id是自动递增的,因此我不会从代码中传递它。

The number of arguments match in the model class and in the DB. The id inside database is auto incremented so I am not passing it from the code.

模型类:

@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;
    }

}


推荐答案

您对ActiveJDBC API的使用不正确。

Your use of ActiveJDBC APIs is not correct.


  1. 不需要注释@Table,因为您的模型名称与表名称相对应

  2. 不需要声明属性

  3. 您调用了错误的方法 set

  4. 您有意大利面条代码 userInfo.set(userInfo.getUsername()); -您正在将数据从一个对象设置到同一对象???

  1. Do not need annotation @Table, since your model name corresponds to a table name
  2. Do not need to declare properties
  3. You call the wrong method set
  4. You have spaghetti code userInfo.set(userInfo.getUsername()); - you are setting data from an object to the same object?????

您的模型需要(完整):

Your model needs to be (in its entirety):

public class UserInfo extends Model {}

这就是您所需要的。

如果需要在模型上设置值,则可以:

If you need to set values on a model, you can:

userInfo.set("user_name", userName); 

等。

我建议您阅读文档并尝试自己解决问题,因为您的问题表明您缺乏努力。

I suggest you read the documentation and try to resolve the issues yourself, as your question displays a lack of effort on your part.

这篇关于java.lang.IllegalArgumentException:参数数量必须在org.javalite.activejdbc.Model.set处为偶数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆