有人能看一下,前端数据传递过来了,但因为某些字段没有,就默认为空值。通过dubbo远程调用服务,就会报空指针异常。
dubbo+zookeeper+ssm
代码:
handleAdd() {
//获取表单数据
//获取对应的id数组
console.log(this.formData);
console.log(this.checkitemIds);
//向后台发送请求
axios.post("/checkGroup/add.do?ids[]=" + this.checkitemIds,this.formData).then((res) => {
if (res.data.flag) {
//刷新页面
this.findPage();
this.dialogFormVisible = false;
this.$message.success(res.data.message)
} else {
this.$message.error(res.data.message)
}
//重置表单
this.formData = {};
this.checkitemIds = [];
})
}
controller
@PostMapping("/add")
public Result addCheckGroup(@RequestBody CheckGroup checkGroup, @RequestParam(value = "ids[]") Integer[] ids) {
try {
System.out.println(checkGroup);
System.out.println(ids);
checkGroupService.addCheckGroup(checkGroup, ids);
return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
}
}
异常信息
CheckGroup{id=null, code='q', name='q', helpCode='1', sex='1', remark='1', attention='1', checkItems=null}
[Ljava.lang.Integer;@1e4cdfc9
java.lang.NullPointerException
at com.itheima.controller.CheckGroupController.addCheckGroup(CheckGroupController.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)