0


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

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

方法1:快捷键

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

1.生成有参和无参构造函数
在这里插入图片描述
在这里插入图片描述

publicUser(){}publicUser(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方法
在这里插入图片描述
在这里插入图片描述

publicStringgetUsername(){return username;}publicvoidsetUsername(String username){this.username = username;}publicStringgetPassword(){return password;}publicvoidsetPassword(String password){this.password = password;}publicStringgetCfpassword(){return cfpassword;}publicvoidsetCfpassword(String cfpassword){this.cfpassword = cfpassword;}publicStringgetEmail(){return email;}publicvoidsetEmail(String email){this.email = email;}publicStringgetGender(){return gender;}publicvoidsetGender(String gender){this.gender = gender;}publicintgetAge(){return age;}publicvoidsetAge(int age){this.age = age;}

3.生成toString方法
在这里插入图片描述
在这里插入图片描述

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

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

1.安装插件
在这里插入图片描述
在这里插入图片描述
2.右键-使用插件
在这里插入图片描述

publicUser(){}publicUser(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
 */publicStringgetUsername(){return username;}/**
 * 设置
 * @param username
 */publicvoidsetUsername(String username){this.username = username;}/**
 * 获取
 * @return password
 */publicStringgetPassword(){return password;}/**
 * 设置
 * @param password
 */publicvoidsetPassword(String password){this.password = password;}/**
 * 获取
 * @return cfpassword
 */publicStringgetCfpassword(){return cfpassword;}/**
 * 设置
 * @param cfpassword
 */publicvoidsetCfpassword(String cfpassword){this.cfpassword = cfpassword;}/**
 * 获取
 * @return email
 */publicStringgetEmail(){return email;}/**
 * 设置
 * @param email
 */publicvoidsetEmail(String email){this.email = email;}/**
 * 获取
 * @return gender
 */publicStringgetGender(){return gender;}/**
 * 设置
 * @param gender
 */publicvoidsetGender(String gender){this.gender = gender;}/**
 * 获取
 * @return age
 */publicintgetAge(){return age;}/**
 * 设置
 * @param age
 */publicvoidsetAge(int age){this.age = age;}publicStringtoString(){return"User{username = "+ username +", password = "+ password +", cfpassword = "+ cfpassword +", email = "+ email +", gender = "+ gender +", age = "+ age +"}";}

本文转载自: https://blog.csdn.net/shiqing4387/article/details/127705734
版权归原作者 前端小趴菜~时倾 所有, 如有侵权,请联系我们删除。

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

还没有评论