~!求救 如何获取多行数据插入到数据库中...我弄了两天只能想数据库中插入一条数据...

时间:2021-04-20 21:42:05
    //获取页面传来的数据放入请求中....

public ModelAndView SaveJhwc(HttpServletRequest request,
HttpServletResponse response) throws ODSWebBaseException {
logger.debug("进入--------JhwcCTRL SaveJhwc()---------方法");
ModelAndView view = this.getModelAndView(request);
JhwcReqEvent req = new JhwcReqEvent(
JhwcReqEvent.ODS_TRANSCATIONID_WSDYCFJDPROXY, this
.getEJBSessionid(request));
req.setMethod(JhwcReqEvent.ODS_METHOD_SAVWJHWC);
logger.debug("获取表单数据");
System.out.println("获取表单数据");
String swjg = request.getParameter("swjg");
String nd = request.getParameter("nd");
Random random = new Random();
int xh = random.nextInt(100000);;
double january = Double.parseDouble(request.getParameter("january"));
double february = Double.parseDouble(request.getParameter("february"));
double march = Double.parseDouble(request.getParameter("march"));
double april = Double.parseDouble(request.getParameter("april"));
double may = Double.parseDouble(request.getParameter("may"));
double june = Double.parseDouble(request.getParameter("june"));
double july = Double.parseDouble(request.getParameter("july"));
double august = Double.parseDouble(request.getParameter("august"));
double september = Double.parseDouble(request.getParameter("september"));
double october = Double.parseDouble(request.getParameter("october"));
double nobember = Double.parseDouble(request.getParameter("nobember"));
double december = Double.parseDouble(request.getParameter("december"));
int lb=0;
req.setXh(xh);
req.setLb(lb);
req.setSwjg(swjg);
req.setNd(nd);
req.setJanuary(january);
req.setFebruary(february);
req.setMarch(march);
req.setApril(april);
req.setMay(may);
req.setJune(june);
req.setJuly(july);
req.setAugust(august);
req.setSeptember(september);
req.setOctober(october);
req.setNobember(nobember);
req.setDecember(december);
req.setLrry(req.getSessionID().substring(0, 11));
JhwcResEvent res = (JhwcResEvent) delegate(req);
view.setViewName("/jhwc/jhwc");
logger.debug("结束--------JhwcCTRL SaveJhwc()---------方法");
return view;
}

7 个解决方案

#1




protected ODSGerneralResponseEvent odsDeal(ODSGerneralRequestEvent reqEvent)
throws ODSCoreBaseException {
logger.debug("进入--------JhwcProxy 的 odsDeal()---------方法");
JhwcReqEvent req = (JhwcReqEvent)reqEvent;
String method = req.getMethod();
JhwcResEvent res = null;
logger.debug("CTRL端传过来的method==============" + method);
if (JhwcReqEvent.ODS_METHOD_JHWCFINDALL.equals(method)) {
res=this.FindAllByND(req);
}if(JhwcReqEvent.ODS_METHOD_SAVWJHWC.equals(method)){
res=this.SaveJhwc(req);
}if(JhwcReqEvent.ODS_METHOD_DELETEWJHWC.equals(method)){
res=this.deleteJhwcByXh(req);
}if(JhwcReqEvent.ODS_METHOD_FINDALLSWJG.equals(method)){
res=this.FindAll(req);
}if(JhwcReqEvent.ODS_METHOD_UPDATEINFOSWJG.equals(method)){
res=this.updateInfo(req);
}
logger.debug("退出--------JhwcProxy 的 odsDeal()---------方法");
return res;
}
public JhwcResEvent FindAllByND(JhwcReqEvent req){
Connection con = this.getODSConnection();
JhwcResEvent res = new JhwcResEvent();
JhwcHelper helper = new JhwcHelper();
ArrayList list  = helper.FindAllByND(con, req.getLb(), req.getNd());
res.setList(list);
return res;
}

#2


 //把实体类的数据放到bpo中 调用bpo的Insert方法添加

public void SaveJhwc(Connection con, THxySscxJhwcbVO vo) {
System.out.println("------------开始JhwcHelper.SaveJhwc()方法");
JhwcBPO bpo = new JhwcBPO();
bpo.setXh(vo.getXh());
bpo.setLb(vo.getLb());
bpo.setLrry(vo.getLrry());
bpo.setSwjg(vo.getSwjg());
bpo.setNd(vo.getNd());
bpo.setJanuary(vo.getJanuary());
bpo.setFebruary(vo.getFebruary());
bpo.setMarch(vo.getMarch());
bpo.setApril(vo.getApril());
bpo.setMay(vo.getMay());
bpo.setJune(vo.getJune());
bpo.setJuly(vo.getJuly());
bpo.setAugust(vo.getAugust());
bpo.setSeptember(vo.getSeptember());
bpo.setOctober(vo.getOctober());
bpo.setNobember(vo.getNobember());
bpo.setDecember(vo.getDecember());
System.out.println("------------结束JhwcHelper.SaveJhwc()方法");
try {
bpo.insert(con);
} catch (Exception e) {
System.out.println("saveJhwc错误:" + e);
e.printStackTrace();
}
}

#3


引用 1 楼 senloveyunver 的回复:
Java code

    protected ODSGerneralResponseEvent odsDeal(ODSGerneralRequestEvent reqEvent)
            throws ODSCoreBaseException {
        logger.debug("进入--------JhwcProxy 的 odsDeal()---------……

不是FindAllByND方法..是
//吧页面请求的数据放入实体类中

public JhwcResEvent SaveJhwc(JhwcReqEvent req){
Connection con = this.getODSConnection();
JhwcResEvent res = new JhwcResEvent();
JhwcHelper helper = new JhwcHelper();
THxySscxJhwcbVO vo = new THxySscxJhwcbVO();
vo.setXh(req.getXh());
vo.setLrry(req.getLrry());
vo.setLb(req.getLb());
vo.setSwjg(req.getSwjg());
vo.setNd(req.getNd());
vo.setJanuary(req.getJanuary());
vo.setFebruary(req.getFebruary());
vo.setMarch(req.getMarch());
vo.setApril(req.getApril());
vo.setMay(req.getMay());
vo.setJune(req.getJune());
vo.setJuly(req.getJuly());
vo.setAugust(req.getAugust());
vo.setSeptember(req.getSeptember());
vo.setOctober(req.getOctober());
vo.setNobember(req.getNobember());
vo.setDecember(req.getDecember());
helper.SaveJhwc(con, vo);
res.setFlag(true);
res.setVo(vo);
return res;

}

#4


bpo.insert(con)?

#5


页面是用js实现的增行,每次点击保存总是保持第一行的数据 其他的数据都没有插入到数据库中...弄了两天都没有弄好...请高手指点 要如何获取所有的数据进行批量添加....

#6


引用 4 楼 goodsun00 的回复:
bpo.insert(con)?

框架自带的一个方法sql语句自动生成的添加的参数就是bpo里的字段

#7


具体的逻辑是:先是页面传过来的数据,然后放到req(请求)中,然后吧req(请求)中的数据传到vo(实体类)中,
最后把存放到vo(实体类)中的数据放到bpo中进行数据库添加操作,至于insert方法是自动生成的 ,要添加的字段就是

 JhwcBPO bpo = new JhwcBPO();
        bpo.setXh(vo.getXh());
        bpo.setLb(vo.getLb());
        bpo.setLrry(vo.getLrry());
        bpo.setSwjg(vo.getSwjg());
        bpo.setNd(vo.getNd());
        bpo.setJanuary(vo.getJanuary());
        bpo.setFebruary(vo.getFebruary());
        bpo.setMarch(vo.getMarch());
        bpo.setApril(vo.getApril());
        bpo.setMay(vo.getMay());
        bpo.setJune(vo.getJune());
        bpo.setJuly(vo.getJuly());
        bpo.setAugust(vo.getAugust());
        bpo.setSeptember(vo.getSeptember());
        bpo.setOctober(vo.getOctober());
        bpo.setNobember(vo.getNobember());
        bpo.setDecember(vo.getDecember());

 
 不知道表达的是否清晰....小弟新手.请多多指教

#1




protected ODSGerneralResponseEvent odsDeal(ODSGerneralRequestEvent reqEvent)
throws ODSCoreBaseException {
logger.debug("进入--------JhwcProxy 的 odsDeal()---------方法");
JhwcReqEvent req = (JhwcReqEvent)reqEvent;
String method = req.getMethod();
JhwcResEvent res = null;
logger.debug("CTRL端传过来的method==============" + method);
if (JhwcReqEvent.ODS_METHOD_JHWCFINDALL.equals(method)) {
res=this.FindAllByND(req);
}if(JhwcReqEvent.ODS_METHOD_SAVWJHWC.equals(method)){
res=this.SaveJhwc(req);
}if(JhwcReqEvent.ODS_METHOD_DELETEWJHWC.equals(method)){
res=this.deleteJhwcByXh(req);
}if(JhwcReqEvent.ODS_METHOD_FINDALLSWJG.equals(method)){
res=this.FindAll(req);
}if(JhwcReqEvent.ODS_METHOD_UPDATEINFOSWJG.equals(method)){
res=this.updateInfo(req);
}
logger.debug("退出--------JhwcProxy 的 odsDeal()---------方法");
return res;
}
public JhwcResEvent FindAllByND(JhwcReqEvent req){
Connection con = this.getODSConnection();
JhwcResEvent res = new JhwcResEvent();
JhwcHelper helper = new JhwcHelper();
ArrayList list  = helper.FindAllByND(con, req.getLb(), req.getNd());
res.setList(list);
return res;
}

#2


 //把实体类的数据放到bpo中 调用bpo的Insert方法添加

public void SaveJhwc(Connection con, THxySscxJhwcbVO vo) {
System.out.println("------------开始JhwcHelper.SaveJhwc()方法");
JhwcBPO bpo = new JhwcBPO();
bpo.setXh(vo.getXh());
bpo.setLb(vo.getLb());
bpo.setLrry(vo.getLrry());
bpo.setSwjg(vo.getSwjg());
bpo.setNd(vo.getNd());
bpo.setJanuary(vo.getJanuary());
bpo.setFebruary(vo.getFebruary());
bpo.setMarch(vo.getMarch());
bpo.setApril(vo.getApril());
bpo.setMay(vo.getMay());
bpo.setJune(vo.getJune());
bpo.setJuly(vo.getJuly());
bpo.setAugust(vo.getAugust());
bpo.setSeptember(vo.getSeptember());
bpo.setOctober(vo.getOctober());
bpo.setNobember(vo.getNobember());
bpo.setDecember(vo.getDecember());
System.out.println("------------结束JhwcHelper.SaveJhwc()方法");
try {
bpo.insert(con);
} catch (Exception e) {
System.out.println("saveJhwc错误:" + e);
e.printStackTrace();
}
}

#3


引用 1 楼 senloveyunver 的回复:
Java code

    protected ODSGerneralResponseEvent odsDeal(ODSGerneralRequestEvent reqEvent)
            throws ODSCoreBaseException {
        logger.debug("进入--------JhwcProxy 的 odsDeal()---------……

不是FindAllByND方法..是
//吧页面请求的数据放入实体类中

public JhwcResEvent SaveJhwc(JhwcReqEvent req){
Connection con = this.getODSConnection();
JhwcResEvent res = new JhwcResEvent();
JhwcHelper helper = new JhwcHelper();
THxySscxJhwcbVO vo = new THxySscxJhwcbVO();
vo.setXh(req.getXh());
vo.setLrry(req.getLrry());
vo.setLb(req.getLb());
vo.setSwjg(req.getSwjg());
vo.setNd(req.getNd());
vo.setJanuary(req.getJanuary());
vo.setFebruary(req.getFebruary());
vo.setMarch(req.getMarch());
vo.setApril(req.getApril());
vo.setMay(req.getMay());
vo.setJune(req.getJune());
vo.setJuly(req.getJuly());
vo.setAugust(req.getAugust());
vo.setSeptember(req.getSeptember());
vo.setOctober(req.getOctober());
vo.setNobember(req.getNobember());
vo.setDecember(req.getDecember());
helper.SaveJhwc(con, vo);
res.setFlag(true);
res.setVo(vo);
return res;

}

#4


bpo.insert(con)?

#5


页面是用js实现的增行,每次点击保存总是保持第一行的数据 其他的数据都没有插入到数据库中...弄了两天都没有弄好...请高手指点 要如何获取所有的数据进行批量添加....

#6


引用 4 楼 goodsun00 的回复:
bpo.insert(con)?

框架自带的一个方法sql语句自动生成的添加的参数就是bpo里的字段

#7


具体的逻辑是:先是页面传过来的数据,然后放到req(请求)中,然后吧req(请求)中的数据传到vo(实体类)中,
最后把存放到vo(实体类)中的数据放到bpo中进行数据库添加操作,至于insert方法是自动生成的 ,要添加的字段就是

 JhwcBPO bpo = new JhwcBPO();
        bpo.setXh(vo.getXh());
        bpo.setLb(vo.getLb());
        bpo.setLrry(vo.getLrry());
        bpo.setSwjg(vo.getSwjg());
        bpo.setNd(vo.getNd());
        bpo.setJanuary(vo.getJanuary());
        bpo.setFebruary(vo.getFebruary());
        bpo.setMarch(vo.getMarch());
        bpo.setApril(vo.getApril());
        bpo.setMay(vo.getMay());
        bpo.setJune(vo.getJune());
        bpo.setJuly(vo.getJuly());
        bpo.setAugust(vo.getAugust());
        bpo.setSeptember(vo.getSeptember());
        bpo.setOctober(vo.getOctober());
        bpo.setNobember(vo.getNobember());
        bpo.setDecember(vo.getDecember());

 
 不知道表达的是否清晰....小弟新手.请多多指教