VO对象
ElecUserForm elecUserForm
ElecUser elecUser
对应的表单数据
使用值栈
Service层
public ElecUserForm findElecUser(ElecUserForm elecUserForm) {
String userID = elecUserForm.getUserID();
ElecUser elecUser = elecUserDao.findObjectById(userID);
//PO转VO
ElecUserForm elecUserform =this.POToVO(elecUser);
return elecUserform;
}
private ElecUserForm POToVO(ElecUser elecUser ) {
ElecUserForm elecUserForm = new ElecUserForm();//使用值栈这里就是重新new的对象了
if(elecUser!=null){
elecUserForm.setUserID(elecUser.getUserID());
elecUserForm.setLogonName(elecUser.getLogonName());
elecUserForm.setUserName(elecUser.getUserName());
elecUserForm.setSexID(elecUser.getSexID());
elecUserForm.setJctID(elecUser.getJctID());
elecUserForm.setLogonPwd(elecUser.getLogonPwd());
elecUserForm.setBirthday(String.valueOf(elecUser.getBirthday()!=null && elecUser.getBirthday().equals("") ? elecUser.getBirthday() :""));
elecUserForm.setAddress(elecUser.getAddress());
elecUserForm.setContactTel(elecUser.getContactTel());
elecUserForm.setMobile(elecUser.getMobile());
elecUserForm.setEmail(elecUser.getEmail());;
elecUserForm.setIsDuty(elecUser.getIsDuty());
elecUserForm.setOnDutyDate(String.valueOf(elecUser.getOnDutyDate()!=null && elecUser.getOnDutyDate().equals("") ? elecUser.getOnDutyDate() : "" ));
elecUserForm.setOffDutyDate(String.valueOf(elecUser.getOffDutyDate() != null && elecUser.getOffDutyDate().equals("") ? elecUser.getOffDutyDate() : ""));
elecUserForm.setRemark(elecUser.getRemark());
}
return elecUserForm;
}
action层
public String edit(){
System.out.println("edit");
elecUserForm = elecUserService.findElecUser(elecUserForm);
//使用值栈传递elecUserForm,若不使用值栈则需要保持ElecUserForm的对象为模型对象不改变,也就是当传递过去使用时不再次进行实例化新的ElecUserForm对象
ActionContext.getContext().getValueStack().push(elecUserForm);
initSystemDDl();
return "edit";
}
不使用值栈
Service层
public ElecUserForm findElecUser(ElecUserForm elecUserForm) {
String userID = elecUserForm.getUserID();
ElecUser elecUser = elecUserDao.findObjectById(userID);
//PO转VO
ElecUserForm elecUserform =this.POToVO(elecUser , elecUserForm);
return elecUserform;
}
private ElecUserForm POToVO(ElecUser elecUser,ElecUserForm elecUserForm ) {
//ElecUserForm elecUserForm = new ElecUserForm();//不使用值栈要保存数据原形elecUserForm对象传入后使用原型elecUserForm对象返回
if(elecUser!=null){
elecUserForm.setUserID(elecUser.getUserID());
elecUserForm.setLogonName(elecUser.getLogonName());
elecUserForm.setUserName(elecUser.getUserName());
elecUserForm.setSexID(elecUser.getSexID());
elecUserForm.setJctID(elecUser.getJctID());
elecUserForm.setLogonPwd(elecUser.getLogonPwd());
elecUserForm.setBirthday(String.valueOf(elecUser.getBirthday()!=null && elecUser.getBirthday().equals("") ? elecUser.getBirthday() :""));
elecUserForm.setAddress(elecUser.getAddress());
elecUserForm.setContactTel(elecUser.getContactTel());
elecUserForm.setMobile(elecUser.getMobile());
elecUserForm.setEmail(elecUser.getEmail());;
elecUserForm.setIsDuty(elecUser.getIsDuty());
elecUserForm.setOnDutyDate(String.valueOf(elecUser.getOnDutyDate()!=null && elecUser.getOnDutyDate().equals("") ? elecUser.getOnDutyDate() : "" ));
elecUserForm.setOffDutyDate(String.valueOf(elecUser.getOffDutyDate() != null && elecUser.getOffDutyDate().equals("") ? elecUser.getOffDutyDate() : ""));
elecUserForm.setRemark(elecUser.getRemark());
}
return elecUserForm;
}
action层
public String edit(){
System.out.println("edit");
elecUserForm = elecUserService.findElecUser(elecUserForm);
//使用值栈传递elecUserForm,若不使用值栈则需要保持ElecUserForm的对象为模型对象不改变,也就是当传递过去使用时不再次进行实例化新的ElecUserForm对象
//ActionContext.getContext().getValueStack().push(elecUserForm);
initSystemDDl();
return "edit";
}