首页 新闻 会员 周边

spring 事务管理分析,看懂的帮忙分析一下

0
悬赏园豆:5 [已关闭问题] 关闭于 2016-02-02 10:25

    @Transactional
    public Map save(TradeInvestment tradeInvestment) {
        Map map=new HashMap();
        try{
            Long userId=tradeInvestment.getBaseUserInfo().getBaseUserInfoId();//用户Id
            //用户对象
            user=userDao.getPojoById("com.gdpe.wsd.web.pojo.user.BaseUserInfo", userId);
            String tradeInvestmentNumber=Financing.randomInvestNumber();
          
            //输出ID(控制台输出了一次)           System.out.println(tradeInvestment.getTradeFinancing().getTradeFinancingId());
            TradeFinancing tradeFinancing=(TradeFinancing) tradeFinancingDao.getPojoById("com.gdpe.wsd.manage.pojo.trade.TradeFinancing", tradeInvestment.getTradeFinancing().getTradeFinancingId());
            //账户对象
            FinanceUserAccount financeUserAccount=user.getFinanceUserAccount();
            
            Double amout=tradeInvestment.getTradeInvestmentAmount();
            Double syamount=tradeFinancing.getFinancingAmount()-tradeFinancing.getInvestmentAmount();
            Double abamount=financeUserAccount.getFinanceAvailableBalance();//账户可用余额
            if(amout<=syamount){
                if(amout<=abamount){
                    if(amout>=tradeFinancing.getMinmoney()){
                            String content1="普通标--------人名:"+user.getBaseLoginName()+"-----金额:"+tradeInvestment.getTradeInvestmentAmount();
                            Log.writeFileHQ(content1);    //文件中写入日志多次

                                        tradeInvestment.setTradeInvestmentNumber(tradeInvestmentNumber);//编码
                     tradeInvestment.setTradeInvestmentTime(tradeInvestment.getTradeInvestmentTime());//投资时间
                            tradeInvestment.setTradeInvestmentStatus("0");//已投状态
                            tradeInvestment.setTradeFinancing(tradeFinancing);
                            tradeInvestmentDao.save(tradeInvestment);//保存投资表(对象保存了多次)
                            user=userDao.getPojoById("com.gdpe.wsd.web.pojo.user.BaseUserInfo", userId);
                            map.put("user", user);
                            map.put("msg", "sucess");
                    }else{
                        map.put("user", user);
                        map.put("msg", "minmoney");
                    }
                
                }else{
                    map.put("user", user);
                    map.put("msg", "amoney");
                }
            }else{
                map.put("user", user);
                map.put("msg", "fmoney");
            }
            
        }catch(Exception e){
            map.put("user", user);
            map.put("msg", "fail");
        }
        return map;
    }

 

 

描述:方法加了事务管理

用户ID即(System.out.println(tradeInvestment.getTradeFinancing().getTradeFinancingId());)在控制台输出了一次,但是后面的文件写入日志  和  保存对象却执行了多次  

静以修身!的主页 静以修身! | 初学一级 | 园豆:173
提问于:2015-10-20 10:41
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册