简述下问题:
1、前台页面有个多选框,后台定义了JavaBean,多选框用String数组来接,生成get和set,然后在action中可以获取到参数,但如何通过dao插入到数据库? 我用的是hibernate。for (int i = 0; i < xxxl.length; i++)
{
stu.setXxxl(xxxl);
}
这样插入进去是一个数组,在数据库中也是。。如何获取到数组中的值然后插入? 主要JavaBean中定义的是数组,这里set的也必须是数组,如何把值取出来然后插入? 冰天雪地裸体跪求。。
1、前台页面有个多选框,后台定义了JavaBean,多选框用String数组来接,生成get和set,然后在action中可以获取到参数,但如何通过dao插入到数据库? 我用的是hibernate。for (int i = 0; i < xxxl.length; i++)
{
stu.setXxxl(xxxl);
}
这样插入进去是一个数组,在数据库中也是。。如何获取到数组中的值然后插入? 主要JavaBean中定义的是数组,这里set的也必须是数组,如何把值取出来然后插入? 冰天雪地裸体跪求。。
{
stu.setXxxl(xxxl);
} session.save(stu);
...
...
//添加功能
public ActionForward insertPayoff(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
PayOffForm payoffForm=(PayOffForm)form;
try {
String payoffIds=(String)request.getSession().getAttribute("payoffIds");
System.out.println(payoffIds);
String payoffRegisterTime=request.getParameter("payoff.payoffRegisterTime");
String payoffRegistrar=request.getParameter("payoff.payoffRegistrar");
String [] fileInfoId=request.getParameterValues("fileInfoId");
String [] payId=request.getParameterValues("payId");
String [] payoffBounty=request.getParameterValues("payoffBounty");
String [] payoffSaleroom=request.getParameterValues("payoffSaleroom");
String [] payoffDeduct=request.getParameterValues("payoffDeduct");
String [] payCount=request.getParameterValues("payCount");
HttpSession session=request.getSession();
for(int i=0;i<fileInfoId.length;i++){
Payoff payoff=new Payoff();
FileInfo file=new FileInfo();
Pay pay=new Pay();
file.setFileInfoId(Integer.parseInt(fileInfoId[i]));
payoff.setFileInfo(file);
pay.setPayId(Integer.parseInt(payId[i]));
payoff.setPay(pay);
payoff.setPayoffState(0);
payoff.setPayoffRegistrar(payoffRegistrar);
payoff.setPayoffRegisterTime(payoffRegisterTime);
payoff.setPayoffIds(payoffIds);
System.out.println(payoffBounty[i]);
payoff.setPayoffBounty(Double.parseDouble(payoffBounty[i]));
payoff.setPayoffSaleroom(Double.parseDouble(payoffSaleroom[i]));
payoff.setPayoffDeduct(Double.parseDouble(payoffDeduct[i]));
Double a=Double.parseDouble(payoffBounty[i]);
Double b=Double.parseDouble(payoffSaleroom[i]);
Double c=Double.parseDouble(payoffDeduct[i]);
Double d=Double.parseDouble(payCount[i]);
Double sum=a+b-c+d;
System.out.println(sum);
payoff.setPayoffCount(sum);
payoffService.insertPayoff(payoff);
}
return mapping.findForward("insert");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return mapping.findForward("error");
}
}
给你个批量添加的例子 自己看
for (int i = 0; i < xxxl.length; i++) {
Student stu = new Student();
stu.setUsername(username);
stu.setGender(gender);
stu.setXxkc(xxkc);
stu.setAge(age);
stu.setMinzu(minzu);
stu.setWhcd(whcd);
stu.setFather(father);
stu.setMother(mother);
stu.setHuji(huji);
stu.setTel(tel);
stu.setAddress(address);
stu.setFamily(family);
stu.setCode(code);
stu.setIdno(idno);
stu.setXxxl(xxxl);
stu.setBz(bz);
session.save(stu);
}在循环里面插入也不行。。出来还是一个对象。。
[Ljava.lang.String;@1c3432a