public void allowAllNomalAskInfo(){ List<AskForLeave> list = new ArrayList<>(); //得到请假信息的Id String id = getPara("ids"); String[] ids = id.split(","); for (int i = 0; i <ids.length ; i++) { AskForLeave asc = new AskForLeave(); asc.setId(Integer.valueOf(ids[i])); list.add(asc); } //得到老师的openid String openid = getPara("openid"); //调用service层方法 boolean flag = phoneGetAskInfoService.allowAllNormalAsk(openid, list); //返回审批是否成功 if (flag){ renderSuccess("1"); }else { renderError("0"); } }
public boolean allowAllNormalAsk(String allowopenid, List<AskForLeave> IdList){ boolean succeed = Db.tx(new IAtom() { public boolean run() throws SQLException { String sql = "update sc_askforleave set status='已审批' ,allowopenid='"+allowopenid+"' where id =?"; int[] result = Db.batch(sql,"id",IdList,100); for (int i = 0; i < result.length; i++) { if(result[i] <= 0){ System.out.println("没更新到"); return false; } } return true; } }); return succeed; }
第一个controller层,得到一个字符串1,2,5 我把它切割成数组,然后for循环存入请假类中(请假类中有id这个字段).请假类存入list中,调用service方法,按照文档和我搜索的其它的反馈的例子.我写了一个修改语句(测试过了,语句没问题),然后调用Db.batch,返回的影响条数全是0...怎么破.
6.19更新反馈 自己已解决
public void allowAllNomalAskInfo(){ /*List<AskForLeave> list = new ArrayList<>();*/ List<Record> list = new ArrayList<>(); //得到请假信息的Id String id = getPara("ids"); String[] ids = id.split(","); for (int i = 0; i <ids.length ; i++) { // AskForLeave asc = new AskForLeave(); Record record = new Record(); record.set("id",ids[i]); list.add(record); } //得到老师的openid String openid = getPara("openid"); //调用service层方法 boolean flag = phoneGetAskInfoService.allowAllNormalAsk(openid, list); //返回审批是否成功 if (flag){ renderSuccess("1"); }else { renderError("0"); } }
public boolean allowAllNormalAsk(String allowopenid, List<Record> IdList){ boolean succeed = Db.tx(new IAtom() { public boolean run() throws SQLException { String sql = "update sc_askforleave set status='已审批' ,allowopenid='"+allowopenid+"' where id = ?"; int[] result = Db.batch(sql,"id",IdList,100); for (int i = 0; i < result.length; i++) { if(result[i] <= 0){ System.out.println("没更新到"); return false; } } return true; } }); return succeed; }
项目:JFinal