java吧 关注:1,237,041贴子:12,705,677
  • 5回复贴,共1

求大神改下代码,如何解决不在for循环里操作数据库,

取消只看楼主收藏回复

for(int i=0;i<cardNum;i++){
FlowCard flowCard = new FlowCard();
flowCard.setCardBatchId(flowCardBatch.getBatchNo());
List cardList = flowCardDAO.queryFlowCard();
if(cardList.size()==0){
flowCard.setCardNumber(1000000000000001L);
}else{
FlowCard flowCardNum = flowCardDAO.queryCardMax();
flowCard.setCardNumber(flowCardNum.getCardNumber()+1);
}
flowCard.setBeginTime(flowCardBatch.getPeriodStart());
flowCard.setEndTime(flowCardBatch.getPeriodEnd());
flowCard.setLogTime(date1);
flowCard.setProductId(flowCardBatch.getProductId());
flowCard.setPrice(flowCardBatch.getPrice());
flowCard.setUserId(123);
flowCard.setState(0);
int sum = (int)((Math.random()*9+1)*100000000);
String str = sdf.format(new Date());
String cardPassword = str+""+sum;
flowCard.setCardPassword(cardPassword);
flowCardDAO.addFlowCard(flowCard);
}


1楼2015-11-19 12:06回复
    哪位可以帮忙改下,优化下


    2楼2015-11-19 12:07
    回复


      5楼2015-11-19 12:10
      回复
        谁帮忙优化下,感激不尽,主要就是循环调数据库的问题,框架用的是spring mvc ibatis


        6楼2015-11-19 12:11
        回复


          8楼2015-11-19 12:42
          回复
            自顶


            9楼2015-11-19 12:43
            回复