我在 Hibernate 4.3.5 中定义了一个实体,我正在尝试获取控制器中的值,以便我可以在 JSON 响应中显示它。但是我的 for 循环内容以某种不同的方式打印,如下所示:
System.out.println(emp.toString()+"\n");代码中的结果:
abc.cde.myproject.orm.Employee@599eeded
abc.cde.myproject.orm.Employee@75ffa715
abc.cde.myproject.orm.Employee@152beb23
abc.cde.myproject.orm.Employee@1f2f7ce1
abc.cde.myproject.orm.Employee@484ca3df
这是我使用循环的控制器代码:
@RequestMapping(value="/get_employee_details", method=RequestMethod.GET)
public String updateemployee
(
@RequestParam(value="emp_id", defaultValue="0") Integer emp_id,
@RequestParam(value="name", defaultValue="") String name
)
{
String responseJSON = null;
boolean getStatus = true;
try {
EmployeeDao employeeDao = (EmployeeDao)context.getBean("employeeDao");
Employee employee = null;
List<Employee> empList = employeeDao.findByEmployeeId(emp_id);
if ((empList != null) && (!empList.isEmpty())) {
for(Employee emp : empList){
System.out.println(emp.toString()+"\n");
}
if (getStatus) {
responseJSON = GenericOrmStatusView.OrmResponseToJsonString(true, 1,"List of Names here", true);
} else {
responseJSON = GenericOrmStatusView.OrmStatusToJsonString(false, "Update of EMPLOYEE Record Problem!", true);
}
}
} catch (Throwable th) {
th.printStackTrace();
responseJSON = GenericOrmStatusView.OrmStatusToJsonString(false, th.getMessage(), true);
}
return responseJSON;
}
我的员工实体如下:
@Entity
@Table(name="EMPLOYEE")
public class Employee
{
public int getEmployeeId() {
return EmployeeId;
}
public void setEmployeeId(int EmployeeId) {
this.EmployeeId = EmployeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
弑天下
SMILET
相关分类