struts2 不使用值栈ValueStack 实现 由后台向页面值得传递


VO对象

ElecUserForm elecUserForm


PO对象

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";
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值