gpt4 book ai didi

java - 如何在 Struts 2 中使用 ModelDriven 为 Action 类中的模型对象设置属性值?

转载 作者:行者123 更新时间:2023-11-30 11:24:03 26 4
gpt4 key购买 nike

<分区>

使用这段代码:

StudentAction.java:

public class StudentAction extends ActionSupport implements ModelDriven {

private List studentList;
Student student;
StudentDAO sdo = new StudentDAO();

public String delete() {
System.out.println("delete action");
System.out.println(student.getId()); //not setting value of id

sdo.delete(student.getId());

return SUCCESS;
}

@Override
public Object getModel() {
return student;
}
//getter and setter
}

学生.java:

public class Student  implements java.io.Serializable {
private Long id;
private String name;
private String address;
//getter and setter
}

在 JSP 中:

<s:iterator value="studentList" var="ss">
<s:property value="id"/>
<s:property value="name"/>
<s:property value="address"/>
<a href="delete?id= <s:property value="id"/>">delete</a><br>
</s:iterator><br>

当我将 id 的值从 JSP 传递到 delete 操作时,我想初始化 Studentid 属性(property)。

如何做到这一点?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com