有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javajavax。艾尔。PropertyNotFoundException:

我在春天工作。我无法在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";     
}

秀螺柱。jsp

<table>
    <c:forEach var="stud" items="${studlist} }">
        <tr><td>${stud.Name}</td></tr>
    </c:forEach>
</table>

我得到以下例外:

javax.el.PropertyNotFoundException: Property 'Name' not found on type com.spring.mvc.Student


共 (1) 个答案

  1. # 1 楼答案

    变量名是name而不是Name

    <tr><td>${stud.name}</td></tr>
    

    而不是

    <tr><td>${stud.Name}</td></tr>
    

    同时拆下支架

    items="${studlist}" 
    

    而不是

    items="${studlist} }"