我正在使用Hibernate和Spring MVC。我試圖從兩個表中獲取信息並將其顯示在一個jsp頁面中。這裏是我的表:在JSP頁面中顯示數據時獲取java.lang.NumberFormatException
表名:學生
student_id studentName
1. Jason Stathum
表名:studentdetails
studentDetailsid FatherName MotherName student_id
1 Mr.X Mrs. Y 1
在我的JSP頁面中我想這樣的顯示數據:
Sl# Student Father Mother
1 Jason Stathum Mr.X Mrs.Y
當我運行我的應用程序,看看我得到以下錯誤消息的數據:
HTTP狀態500 - 發生處理JSP頁面/WEB-INF/views/studentlist.jsp例外第29行 根源 java.lang.NumberFormatException:對於輸入字符串:「FatherName」 java.lang.NumberFormatException.forInputString(Unknown Source) java.lang.Integer.parseInt(Unknown Source) java.lang.Integer.parseInt(Unknown Source) ....和許多其他行...
我已經包括我的代碼下面,你能告訴我我做錯了什麼嗎?
非常感謝您
實體:學生
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="student_id", nullable= false)
private Integer studentId;
private String studentName;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="student_id", referencedColumnName="student_id")
private List<StudentDetails> studentDetails = new ArrayList<StudentDetails>();
// Getters and Setters
public Integer getStudentId() {
return studentId;
}
public void setStudentId(Integer studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public List<StudentDetails> getStudentDetails() {
return studentDetails;
}
public void setStudentDetails(List<StudentDetails> studentDetails) {
this.studentDetails = studentDetails;
}
實體:StudentDetails
@Entity
@Table(name = "studentDetails")
public class StudentDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer studentDetailsId;
private String FatherName;
private String MotherName;
// Getters and Setters
public Integer getStudentDetailsId() {
return studentDetailsId;
}
public void setStudentDetailsId(Integer studentDetailsId) {
this.studentDetailsId = studentDetailsId;
}
public String getFatherName() {
return FatherName;
}
public void setFatherName(String fatherName) {
FatherName = fatherName;
}
public String getMotherName() {
return MotherName;
}
public void setMotherName(String motherName) {
MotherName = motherName;
}
控制器
@RequestMapping(value="studentlist", method = RequestMethod.GET)
public String getRecords(Model map)
{
List<Student> student = studentService.getAll();
map.addAttribute("student", student);
return "studentlist";
}
StudentDaoImpl
@Override
@SuppressWarnings("unchecked")
public List<Student> getAll() {
return getSessionFactory().openSession().createQuery("FROM Student").list();
}
JSP頁面:studentlist
<c:if test="${!empty student}">
<table class="studentTable">
<tr>
<th>Sl#</th>
<th>Name</th>
<th>Father</th>
<th>Mother</th>
</tr>
<c:set var="count" value="0" scope="page" />
<c:forEach items="${student}" var="row">
<c:set var="count" value="${count + 1}" scope="page"/>
<tr>
<td>${count}</td>
<td>${row.studentName}</td>
<td>${row.studentDetails.FatherName}</td> <--- this is line 29
<td>${row.studentDetails.MotherName}</td>
</tr>
</c:forEach>
</table>
</c:if>
發佈整個堆棧跟蹤可能有助於找到根本原因。 – 2014-09-10 19:55:05