system error
来源:7-4 新增部门、部门层级树、更新部门接口自测

慕码人5437048
2020-02-09
这个system error是啥原因?
2020-02-09 13:02:58.521 [http-nio-8080-exec-7] INFO com.mmall.common.HttpInterceptor - request completed. url:http://localhost:8080/sys/dept/save.json, cost:53 2020-02-09 13:03:01.901 [http-nio-8080-exec-8] INFO com.mmall.common.HttpInterceptor - request start. url:http://localhost:8080/sys/dept/save.json, params:{"name":["技术部"],"seq":["1"],"remark":["技术部"]} 2020-02-09 13:03:01.906 [http-nio-8080-exec-8] ERROR com.mmall.common.SpringExceptionResolver - unknow json exception, url:http://localhost:8080/sys/dept/save.json org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parent_id' not found. Available parameters are [name, id, param3, parentId, param1, param2]
写回答
4回答
-
你好,你sql里parent_id必须有值,而你没设置,如果也没给定默认值,就会出错。
其实,你可以具体看一下异常,这里的文案很明确的指出是mybatis里parent_id找不到032020-02-10 -
慕码人5437048
提问者
2020-02-09
BeanValidator
public class BeanValidator { private static ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); private static <T> Map<String,String> validate(T t, Class... groups){ Validator validator = validatorFactory.getValidator(); Set validateResult = validator.validate(t,groups); if(validateResult.isEmpty()){ return Collections.emptyMap(); }else { LinkedHashMap errors = Maps.newLinkedHashMap(); Iterator iterator = validateResult.iterator(); while(iterator.hasNext()){ ConstraintViolation violation = (ConstraintViolation) iterator.next(); errors.put(violation.getPropertyPath().toString(),violation.getMessage()); } return errors; } } public static Map<String,String> validateList(Collection<?> collection){ Preconditions.checkNotNull(collection); Iterator iterator = collection.iterator(); Map errors; do{ if(!iterator.hasNext()){ return Collections.emptyMap(); } Object object = iterator.next(); errors = validate(object,new Class[0]); }while (errors.isEmpty()); return errors; } public static Map<String,String> validateObject(Object first,Object... objects){ if(objects!=null && objects.length>0){ return validateList(Lists.asList(first,objects)); }else { return validate(first,new Class[0]); } } public static void check(Object param) throws ParamException{ Map<String,String> map = BeanValidator.validateObject(param); if(MapUtils.isNotEmpty(map)){ throw new ParamException(map.toString()); } } }
00 -
慕码人5437048
提问者
2020-02-09
我在默认里面写了的,还是上面的情况,很苦恼
Controller
@RequestMapping("/save.json") @ResponseBody public JsonData saveDept(DeptParam param){ sysDeptService.save(param); return JsonData.success(); }
Service
@Resource private SysDeptMapper sysDeptMapper; public void save(DeptParam param){ BeanValidator.check(param); if(checkExist(param.getParentId(),param.getName(),param.getId())){ throw new ParamException("同一层级下存在相同名称的部门"); } SysDept dept = SysDept.builder() .name(param.getName()) .parentId(param.getParentId()) .seq(param.getSeq()) .remark(param.getRemark()).build(); dept.setLevel(LevelUtil.calculateLevel(getLevel(param.getParentId()),param.getParentId())); dept.setOperator("system");//TODO: dept.setOperateIp("127.0.0.1");//TODO: dept.setOperateTime(new Date()); sysDeptMapper.insertSelective(dept); }
DeptParam
public class DeptParam { private Integer id; @NotBlank(message = "部门名称不可以为空") @Length(max = 15,min=2,message = "部门名称需要在2-15个字之间") private String name; private Integer parentId=0; @NotNull(message = "展示顺序不可以为空") private Integer seq; @Length(max = 150,message = "备注的长度不能超过150个字以内") private String remark; }
00 -
慕码人5437048
提问者
2020-02-09
设置了等于0的,所以很苦恼啊
00
相似问题