详细写出employee的bean
时间: 2023-08-26 20:03:46 浏览: 176
employee-service-kotlin:尝试使用Spring Boot Kotlin的样本服务
好的,这里是一个员工(employee)的 Java Bean 示例:
```java
public class Employee {
private int id;
private String firstName;
private String lastName;
private String department;
private double salary;
// 构造函数
public Employee(int id, String firstName, String lastName, String department, double salary) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.department = department;
this.salary = salary;
}
// getter 和 setter 方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
// toString 方法
@Override
public String toString() {
return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", department=" + department
+ ", salary=" + salary + "]";
}
}
```
这个 Java Bean 包含了员工的 ID、名字、姓氏、部门和薪水等属性。它有一个构造函数,用于创建一个新的 Employee 对象,并包含 getter 和 setter 方法,用于获取和设置对象的属性。此外,它还有一个 toString 方法,用于将 Employee 对象转换为字符串以便输出。
阅读全文