我正在研究春天。我无法在 JSP 中显示列表项。它说:Property not found on type java.lang.String
。我有一个 POJO 类Student
:
public class Student {
private Integer age;
private String name;
private Integer id;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
}
在我的控制器类中,我获取学生列表并将其分配给列表并将列表添加到模型属性中。如下。
@RequestMapping("/getstuds")
public String getstudents(@ModelAttribute Student student, ModelMap model){
StudentDAO studentDAO = (StudentJDBCTemplate)applicationContext.getBean("studentJDBCTemplate");
List<Student> students = studentDAO.listStudents();
model.addAttribute("studlist",students);
System.out.println(students.iterator().next().getName());
return "showstuds";
}
showstuds.jsp
<table>
<c:forEach var="stud" items="${studlist} }">
<tr><td>${stud.Name}</td></tr>
</c:forEach>
</table>
我得到以下异常:
javax.el.PropertyNotFoundException:在类型 com.spring.mvc.Student 上找不到属性“名称”