81,090
社区成员
发帖
与我相关
我的任务
分享
public class EditEmployeeAction extends ActionSupport{
private int empId;
private String empName;
private Date empBirth;
//......
public String getEmpName(){
return this.empName;
}
@RequiredFieldValidator(message="姓名不能为空")
@RequiredStringValidator(message="请填写姓名")
public void setEmpName(String value){
this.empName = value;
}
// 省略其它属性和getter、setter方法
public String execute(){
try{
// 打开数据库
EmployeeDao dao = new EmployeeDao();
Employee emp = new dao.getById(this.empId);
if(this.empName == null){
// empName == null,说明此次访问是重定向过来,而不是通过表单提交的
this.empName = emp.getName();
this.empBirth = emp.getBirth();
// ......
}else{
emp.setName(this.empName);
emp.setBirth(this.empBirth);
//......
dao.update(emp);
}
}catch(Throwable ex){
// 异常处理代码
}finally{
// 关闭数据库
}
}
}
if(ServletActionContext.getRequest().getMethod().equalsIgnoreCase("GET"))