我正在使用spring boot,restful和angularsjs,我有一种添加新代理的方法,还有她的代码
$scope.addagent=function(d)
{
var createagent=d+"-"+Math.random().toString(36).slice(-8)+"-"+Math.random().toString(36).slice(-8);
var req = {
method: 'POST',
url: 'http://localhost:8080/agent/addagent/',
data: { 'message' : createagent }
}
$http(req).success(function(data){alert("ok")});
}
我的休息Controlleur:
@RequestMapping(value=("addagent/"), method=RequestMethod.POST)
public void AddAgent( String message)
{
String[] parts=message.split("-");
Agent ag=new Agent();
ag.setCin(parts[0]);
ag.setLogin(parts[1]);
ag.setPassword(parts[2]);
ag.setAdmin(null);
ag.setStructurenotifications(null);
agentservice.createAgent(ag);
}
但是当我点击addagent()按钮时,我收到此错误:
java.lang.NullPointerException: null
at com.gatewayproject.AgentRestControlleur.AddAgent(AgentRestControlleur.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
此错误引用
String[] parts=message.split("-");
我认为获取post方法的值存在问题?