1. 程式人生 > >從一個Controller傳遞引數到另一個Controller(addFlashAttribute)

從一個Controller傳遞引數到另一個Controller(addFlashAttribute)

搞了半小時才成功

/** 
* 線上支付:整理支付單資訊 
* @param request 
* @param response 
* @param attr 
* @return  paymentbill 
*/  
@RequestMapping(value = "paymentbill")  
public ModelAndView paymentbill(HttpServletRequest request,HttpServletResponse response,RedirectAttributes attr) {  
        if(!chkOfLogin(request,response)){  
             return null;  
        }  
          
        String groupCode =request.getParameter("groupCode");  
        String groupId=(new GroupUtil()).getGroupbyCode(groupCode).getId();  
        Group pro = groupServ.getGroup(groupId);  
        String bankType = request.getParameter("bankType");  
        List<BankPayOnlineInfo> bankpayonlineinfo = bankpayonlineinfoServ.getBankPayOnlineInfoByBankType(groupId,bankType);  
        Member member = getMember(request);  
          
        //支付單資訊  
  
        ///收款方資訊:  
        String pk_group = bankpayonlineinfo.get(0).getGroupId();//集團ID  
        String cpayeeaccname = pro.getName();//收款方戶名(集團名字)  
        String cpayeebanktype = bankpayonlineinfo.get(0).getBankType();//銀行簡拼  
        String cpayeeaccnum = bankpayonlineinfo.get(0).getMerchantNo();//收款方賬號(商戶號)  
        String cpayeebankaccid = bankpayonlineinfo.get(0).getBankAccount();//收款方銀行賬戶(銀行賬號)  
        String cpayeeid = bankpayonlineinfo.get(0).getCorporationId();//收款方(公司ID)  
          
        ///支付方資訊:  
        String cpayeraccnumid = member.getAccount();//付款方賬號(會員賬號)  
        String cpayerid = member.getBusinessName();//付款方(企業名稱)  
        String cpayerbankaccid = member.getACNo();//付款方銀行賬戶(銀行賬號)  
        String cpayeraccname = member.getName();//付款方戶名(姓名)  
          
        ///支付單其他資訊:  
        String vpaymentbillcode = cpayeraccnumid+UUIDMake.produceUID();//支付單編號(會員賬號+UUID)  
        String billmaker = cpayeraccnumid;//制單人(會員賬號)  
        String dbilldate = DataTimeUtil.getCurrentTime();//制單時間  
        String remark = request.getParameter("remark");//備註資訊  
        int fpaymentstatus = 1;//支付狀態(1=待支付,2=支付中,3=支付成功,4=支付失敗  
        String payfailreaon = null;//支付失敗原因  
        int corigcurrencyid = 01;//人民幣  
        String dtradedate = DataTimeUtil.getCurrentTime();//交易日期  
        String modifier = cpayeraccnumid;//最後修改人(會員賬號)  
        String modifiedtime = DataTimeUtil.getCurrentTime();//最後修改時間  
        BigDecimal money;//充值金額         支付金額    npaymentamount  
        String moneystr = request.getParameter("topupmoney");  
        if(StringUtils.isBlank(moneystr)){  
            throw new BusinessException(ShopExceptionConstant.ERROR, "金額非法");  
        }  
        try {  
            money = new BigDecimal(moneystr);  
        } catch (Exception e) {  
            logger.error(e.getMessage());  
            throw new BusinessException(ShopExceptionConstant.ERROR, "金額非法");  
        }  
          
        PaymentBill paymentbill = new PaymentBill();  
        //收款方資訊:  
        paymentbill.setPk_group(pk_group);  
        paymentbill.setCpayeeaccname(cpayeeaccname);  
        paymentbill.setCpayeebanktype(cpayeebanktype);  
        paymentbill.setCpayeeaccnum(cpayeeaccnum);  
        paymentbill.setCpayeebankaccid(cpayeebankaccid);  
        paymentbill.setCpayeeid(cpayeeid);        
        //支付方資訊:  
        paymentbill.setCpayeraccname(cpayeraccname);  
        paymentbill.setCpayeraccnumid(cpayeraccnumid);  
        paymentbill.setCpayerbankaccid(cpayerbankaccid);  
        paymentbill.setCpayerid(cpayerid);  
        //支付單其他資訊:  
        paymentbill.setBillmaker(billmaker);  
        paymentbill.setCorigcurrencyid(corigcurrencyid);  
        paymentbill.setDbilldate(dbilldate);  
        paymentbill.setDtradedate(dtradedate);  
        paymentbill.setFpaymentstatus(fpaymentstatus);  
        paymentbill.setModifiedtime(modifiedtime);  
        paymentbill.setModifier(modifier);  
        paymentbill.setMoney(money);  
        paymentbill.setPayfailreaon(payfailreaon);  
        paymentbill.setRemark(remark);  
        paymentbill.setVpaymentbillcode(vpaymentbillcode);  
        //儲存支付單資訊  
        paymentbillServ.insertPaymentBill(paymentbill);  
        //傳遞的引數  
        attr.addFlashAttribute("pk_group", pk_group);  
        attr.addFlashAttribute("cpayeebanktype",cpayeebanktype);  
        attr.addFlashAttribute("vpaymentbillcode",vpaymentbillcode);  
        attr.addFlashAttribute("flag", "paymentbill");  
        //選擇支付平臺Controller地址  
	return new ModelAndView("redirect:/paybill/controller/payofbank");  
}
/**  
* 線上支付:選擇支付平臺  
*/  
@RequestMapping(value = "payofbank")  
public ModelAndView payofbank(HttpServletRequest request,HttpServletResponse response,RedirectAttributes attr) {  
	//Map<String, String> map=(Map<String, String>) attr.getFlashAttributes();
	//Map<String, Object> maps=RequestContextUtils.getOutputFlashMap(request);
	//上面兩種方法失敗告終
	Map<String, String> map=(Map<String, String>)RequestContextUtils.getInputFlashMap(request);  
	String groupId = (String) map.get("pk_group");  
	String bankType = (String) map.get("cpayeebanktype");  
	String vpaymentbillcode = (String) map.get("vpaymentbillcode");  
	List<BankPayOnlineInfo> bankpayonlineinfo = bankpayonlineinfoServ.getBankPayOnlineInfoByBankType(groupId,bankType);  
	PaymentBill paymentbill = paymentbillServ.getPaymentBill(vpaymentbillcode);  
	//下面的地址沒寫  
	return new ModelAndView("redirect:"); 
} 
大概就是這個樣子