JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)

Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)

方法1:快捷键

快捷键:
  alt+insert
  或alt+fn+insert

1.生成有参和无参构造函数
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第1张图片
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第2张图片

 public User() {
    }

    public User(String username, String password, String cfpassword, String email, String gender, int age) {
        this.username = username;
        this.password = password;
        this.cfpassword = cfpassword;
        this.email = email;
        this.gender = gender;
        this.age = age;
    }

2.生成Getter和Setter方法
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第3张图片
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第4张图片

 public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCfpassword() {
        return cfpassword;
    }

    public void setCfpassword(String cfpassword) {
        this.cfpassword = cfpassword;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

3.生成toString方法
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第5张图片
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第6张图片

 @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", cfpassword='" + cfpassword + '\'' +
                ", email='" + email + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                '}';
    }

方法2:插件-1s生成标准JavaBean

1.安装插件
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第7张图片
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第8张图片
2.右键-使用插件
JavaSE学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)_第9张图片

public User() {
}

public User(String username, String password, String cfpassword, String email, String gender, int age) {
    this.username = username;
    this.password = password;
    this.cfpassword = cfpassword;
    this.email = email;
    this.gender = gender;
    this.age = age;
}

/**
 * 获取
 * @return username
 */
public String getUsername() {
    return username;
}

/**
 * 设置
 * @param username
 */
public void setUsername(String username) {
    this.username = username;
}

/**
 * 获取
 * @return password
 */
public String getPassword() {
    return password;
}

/**
 * 设置
 * @param password
 */
public void setPassword(String password) {
    this.password = password;
}

/**
 * 获取
 * @return cfpassword
 */
public String getCfpassword() {
    return cfpassword;
}

/**
 * 设置
 * @param cfpassword
 */
public void setCfpassword(String cfpassword) {
    this.cfpassword = cfpassword;
}

/**
 * 获取
 * @return email
 */
public String getEmail() {
    return email;
}

/**
 * 设置
 * @param email
 */
public void setEmail(String email) {
    this.email = email;
}

/**
 * 获取
 * @return gender
 */
public String getGender() {
    return gender;
}

/**
 * 设置
 * @param gender
 */
public void setGender(String gender) {
    this.gender = gender;
}

/**
 * 获取
 * @return age
 */
public int getAge() {
    return age;
}

/**
 * 设置
 * @param age
 */
public void setAge(int age) {
    this.age = age;
}

public String toString() {
    return "User{username = " + username + ", password = " + password + ", cfpassword = " + cfpassword + ", email = " + email + ", gender = " + gender + ", age = " + age + "}";
}

你可能感兴趣的:(JavaSE学习,intellij-idea,学习,java)