org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是java.lang.NumberFormatException:对于输入字符串:“”
我正在尝试仅使用注释,java,JSP,spring数据,spring mvc和mongo db构建Web应用程序。
我的工作大部分都在工作,但是当我尝试使用多选列表创建JSP表单时,我收到了标题错误。
我正在尝试创建代理对象并将其保存到mongodb数据库。多选框将传回所选对象的字符串ID。代理对象具有需要使用多选列表填充的列表。
以下是chrome dev工具的响应数据:
id: name:Test1 type:MOB
attributeList[]:687a1964-4179-4631-832b-e23b34300840
personalityTraitList[]:8b321f3c-6398-4bc4-afc6-e6c7e4a6a3e3
skillList[]:53090226-0f54-4121-90c0-4d3a188aa5f8
triggerList[]:923048ef-7a4d-42e3-8691-2d2e9603e79b
behaviorTreeList[]:84966b7a-fb53-4f64-be2a-203ae3743250
这是第一个多选框的html。它们都是一样的。
<td align="left">
<select size="10" id="selectedAttributes" multiple="multiple" name="attributeList[${attribute.id}]" style="width: 130px;"></select>
</td>
这是控制器保存请求映射:
@RequestMapping(value = "/AgentManager/save", method = RequestMethod.POST)
public View createAgent(@ModelAttribute Agent agent, ModelMap model)
{
if(StringUtils.hasText(agent.getId()))
{
agentService.updateAgent(agent);
} else
{
agentService.addAgent(agent);
}
return new RedirectView("/MotherNatureEmulator/AgentManager");
}
如果要在保存代理时ID字段为空,代理服务将创建一个随机UUID。
这是堆栈跟踪:
java.lang.NumberFormatException:对于输入字符串:“” java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) java.lang.Integer.parseInt(Integer.java:504) java.lang.Integer.parseInt(Integer.java:527) org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:969) org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902) org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:740) org.springframework.validation.DataBinder.doBind(DataBinder.java:636) org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191) org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:112) org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:153) org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106) org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) javax.servlet.http.HttpServlet.service(HttpServlet.java:647) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
我尝试创建自定义数据绑定器,但这没有帮助。
有人能指导我做正确的事吗?这是我第一次尝试自己创建一个网络应用程序。
这是Agent类:
@Document(collection = "AgentCollection")
public class Agent
{
@Id
private String _id;
private String _name;
private String _type;
private ArrayList<String> _actionList;
private ArrayList<String> _attributeList;
private ArrayList<String> _behaviorTreeList;
private ArrayList<String> _itemList;
private ArrayList<String> _personalityTraitList;
private ArrayList<String> _skillList;
private ArrayList<String> _triggerList;
public String getId()
{
return _id;
}
public void setId(String id)
{
_id = id;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public String getType()
{
return _type;
}
public void setType(String type)
{
_type = type;
}
public ArrayList<String> getAttributeList()
{
return _attributeList;
}
public void setAttributeList(final ArrayList<String> attributeList)
{
_attributeList = attributeList;
}
public ArrayList<String> getPresonalityTraitList()
{
return _personalityTraitList;
}
public void setPersonalityTraitList(final ArrayList<String> personalityTraitList)
{
_personalityTraitList = personalityTraitList;
}
public ArrayList<String> getSkillList()
{
return _skillList;
}
public void setSkillList(final ArrayList<String> skillList)
{
_skillList = skillList;
}
public ArrayList<String> getActionList()
{
return _actionList;
}
public void setActionList(final ArrayList<String> actionList)
{
_actionList = actionList;
}
public ArrayList<String> getTriggerList()
{
return _triggerList;
}
public void setTriggerList(final ArrayList<String> triggerList)
{
_triggerList = triggerList;
}
public ArrayList<String> getItemList()
{
return _itemList;
}
public void setItemList(final ArrayList<String> itemList)
{
_itemList = itemList;
}
public ArrayList<String> getBehaviorTreeList()
{
return _behaviorTreeList;
}
public void setBehaviorTreeList(final ArrayList<String> behaviorTreeList)
{
_behaviorTreeList = behaviorTreeList;
}
}
谢谢, 马特
答案 0 :(得分:0)
Spring不处理空方括号。总结一下,你可以使用
但不是