如果可以直接set一个Ret进去,那不是更加方便吗?
我前端需要知道是那个Id校验失败!!
下面是我的笨办法:
先设id,再取回来,再set错误信息!
package com.analysis.validator; import com.jfinal.core.Controller; import com.jfinal.validate.Validator; public class ReportAddValidator extends Validator { protected void validate(Controller c) { setShortCircuit(true); validateRequired("financialMonthReport.saleAmount", "id", "saleAmount"); validateRequired("financialMonthReport.budget", "id", "budget"); validateRequired("financialMonthReport.completeRate", "id", "completeRate"); validateRequired("financialMonthReport.wjAmount", "id", "wjAmount"); validateRequired("financialMonthReport.wjRate", "id", "wjRate"); validateRequired("financialMonthReport.lsAmount", "id", "lsAmount"); } protected void handleError(Controller c) { String errId = c.getAttr("id"); switch (errId){ case "saleAmount": c.setAttr("msg","当月销售收入,不能为空!"); break; case "budget": c.setAttr("msg","年预算,不能为空!"); break; case "completeRate": c.setAttr("msg","完成率,不能为空!"); break; case "wjAmount": c.setAttr("msg","五金当月销售,不能为空!"); break; case "wjRate": c.setAttr("msg","五金占比,不能为空!"); break; case "lsAmount": c.setAttr("msg","管道当月销售,不能为空!"); break; } c.renderJson(); } }
项目:JFinal
在 jfinal-club 项目中搜索 setRet 与 getRet ,有实际的例子可以参考