如何在delete()中设置Student的id值?
问题描述:
我想在删除$ c $中初始化
学生
的 id
c>行动
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
}
Student.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>
将值从JSP传递到 delete
操作我想使用此代码初始化学生
的 id
。怎么做?
While passing value from JSP to delete
action I want to initialize Student
's id
by using this code. How to do this?
答
使用操作字段设置参数 id
:
Use the action field to set the parameter id
:
public class StudentAction extends ActionSupport {
private List studentList;
Student student;
StudentDAO sdo = new StudentDAO();
private Long id;
//getter and setter
public String delete() {
System.out.println("delete action");
System.out.println(getId());
sdo.delete(getId());
return SUCCESS;
}
}
如果你想实现 ModelDriven 你应该为你的模特添加代码
One more thing if you want to implement ModelDriven
you should add the code for your model
private Student model = new Student();
public Object getModel() {
return model;
}
代码就像文档示例。