Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)
方法1:快捷键
快捷键:
alt+insert
或alt+fn+insert
1.生成有参和无参构造函数
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方法
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方法
文章来源:https://www.toymoban.com/news/detail-518721.html
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
", cfpassword='" + cfpassword + '\'' +
", email='" + email + '\'' +
", gender='" + gender + '\'' +
", age=" + age +
'}';
}
方法2:插件-1s生成标准JavaBean
1.安装插件
2.右键-使用插件
文章来源地址https://www.toymoban.com/news/detail-518721.html
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学习之路:Idea小技巧一键生成标准JavaBean(一键生成构造方法和Setter和Getter方法)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!