在线等!java 从list取值的问题。 30
list中已经有数据了,不是从数据库中获取的,要从list中每次提取10个,分别插入数据库,请问如何获取?preForInsert(cusID,date1,date2)这...
list中已经有数据了,不是从数据库中获取的,要从list中每次提取10个,分别插入数据库,请问如何获取? preForInsert(cusID, date1, date2)这个事list。在现有的代码基础上修改,每次都只能插入10条。
public List saveRequestInfo(CustomerInfoMaster customer, Date date1, Date date2, String cusID) {
List requestnolist = new ArrayList();
OrderDetail detail;
RequestDetail detail1;
RequestInfo resInfo;
String id = seikyuDAO.makeRequestID();
Date date = (Date) seikyuDAO.getNow().get(0);
resInfo = new RequestInfo();
resInfo.setCustomerinfomaster(customer);
resInfo.setRequestmakedate(date);
resInfo.setRequestno(id);
requestnolist.add(id);
int rowNO=0;
for (Object obj : preForInsert(cusID, date1, date2)) {
rowNO++;
detail = (OrderDetail) obj;
detail1 = new RequestDetail();
detail1.setRequestDetailPK(new RequestDetailPK(resInfo, rowNO));
detail1.setUnitID(detail.getUnitID());
detail1.setUnitName(detail.getUnitName());
detail1.setUnit(detail.getUnit());
detail1.setUnitprice(detail.getUnitprice());
detail1.setAmount(detail.getAmount());
resInfo.addDetails(detail1);
}
seikyuDAO.saveRequestInfo(resInfo, date1, date2);
return requestnolist;
}
我每次同时插入两个数据库的,好比一张订单表RequestInfo ,每张订单只能有10件物品RequestDetail 。 超过10件就另外再写一张订单! 展开
public List saveRequestInfo(CustomerInfoMaster customer, Date date1, Date date2, String cusID) {
List requestnolist = new ArrayList();
OrderDetail detail;
RequestDetail detail1;
RequestInfo resInfo;
String id = seikyuDAO.makeRequestID();
Date date = (Date) seikyuDAO.getNow().get(0);
resInfo = new RequestInfo();
resInfo.setCustomerinfomaster(customer);
resInfo.setRequestmakedate(date);
resInfo.setRequestno(id);
requestnolist.add(id);
int rowNO=0;
for (Object obj : preForInsert(cusID, date1, date2)) {
rowNO++;
detail = (OrderDetail) obj;
detail1 = new RequestDetail();
detail1.setRequestDetailPK(new RequestDetailPK(resInfo, rowNO));
detail1.setUnitID(detail.getUnitID());
detail1.setUnitName(detail.getUnitName());
detail1.setUnit(detail.getUnit());
detail1.setUnitprice(detail.getUnitprice());
detail1.setAmount(detail.getAmount());
resInfo.addDetails(detail1);
}
seikyuDAO.saveRequestInfo(resInfo, date1, date2);
return requestnolist;
}
我每次同时插入两个数据库的,好比一张订单表RequestInfo ,每张订单只能有10件物品RequestDetail 。 超过10件就另外再写一张订单! 展开
5个回答
展开全部
这还不简单嘛? 根据你的代码,存储数据的list应该是preForInsert(cusID, date1, date2) ,那你这样写呗:List list = preForInsert(cusID, date1, date2); 这样不就能够限制list的大小了吗
核心代码:
List list = preForInsert(cusID, date1, date2);
int size = list.size();
if (size > 10)
{
size = 10;
}
for (int i = 0; i < size; i++)
{
detail = (OrderDetail) list.get(i);
detail1 = new RequestDetail();
detail1.setRequestDetailPK(new RequestDetailPK(resInfo, i + 1));
detail1.setUnitID(detail.getUnitID());
detail1.setUnitName(detail.getUnitName());
detail1.setUnit(detail.getUnit());
detail1.setUnitprice(detail.getUnitprice());
detail1.setAmount(detail.getAmount());
resInfo.addDetails(detail1);
}
核心代码:
List list = preForInsert(cusID, date1, date2);
int size = list.size();
if (size > 10)
{
size = 10;
}
for (int i = 0; i < size; i++)
{
detail = (OrderDetail) list.get(i);
detail1 = new RequestDetail();
detail1.setRequestDetailPK(new RequestDetailPK(resInfo, i + 1));
detail1.setUnitID(detail.getUnitID());
detail1.setUnitName(detail.getUnitName());
detail1.setUnit(detail.getUnit());
detail1.setUnitprice(detail.getUnitprice());
detail1.setAmount(detail.getAmount());
resInfo.addDetails(detail1);
}
展开全部
应该不难,但是就是你描述的不明白这点让人很无奈。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码写的很难看....
看这样的我脑袋就想晕..
写的是太混乱了..
看这样的我脑袋就想晕..
写的是太混乱了..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把for循环改成do while
代码的确很丑陋
代码的确很丑陋
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询