Eclipse如何快速创建POJO?
1、新建PojoTest类
2、加入成员变量
3、加入setter/getter
Alt+Shft+S 或者 右键菜单里选择 “Source”。弹出菜单里选择“Generate Setters and Getters”
勾选需要生成setter/getter方法的字段,
点击“OK”,添加好Setter/Getter方法。
4、添加构造函数
Alt+Shft+S 或者 右键菜单里选择 “Source”。弹出菜单里选择“Generate Constructor using fields”
勾选构造函数需要用到的字段,
点“OK”。
一个POJO类就完成了
package shortcut.demo; public class PojoTest { String name; int age; String address; public PojoTest(String name, int age, String address) { super(); this.name = name; this.age = age; this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
时间: 2024-11-05 14:52:54