我在应用程序中为表employee创建了一个类。这是课程
package com.bct.internal.form.model;
public class Employee {
int id;
String name;
int salary;
String designation;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public void setDesignation(String designation) {
this.designation = designation;
}
@Override
public String toString() {
return "Employee [ID=" + id + ", NAME=" + name
+ ", SALARY=" + salary + ", DESIGNATION=" + designation + "]";
}
}
我在控制器中传递该列的值。
public static final class EmployeeMapper implements RowMapper<Employee>
{
public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
Employee employee = new Employee();
employee.setId(id);
employee.setName(rs.getString("name"));
employee.setSalary(salary);
employee.setDesignation(rs.getString("designation"));
return employee;
}
}
但是,对于身份证和工资,“工资不能解析为变量”。
这是什么问题..请帮助我..
对不起,我英语不好。
最佳答案
它应该是
Employee employee = new Employee();
employee.setId(rs.getInt("id")); //or (1)
employee.setName(rs.getString("name"));//or (2)
employee.setSalary(rs.getInt("salary"));//or (3)
employee.setDesignation(rs.getString("designation"));//or (4)
return employee;