gpt4 book ai didi

java - 请求处理失败;嵌套异常是 java.lang.NumberFormatException : For input string: ""

转载 作者:行者123 更新时间:2023-12-01 04:11:20 33 4
gpt4 key购买 nike

org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 java.lang.NumberFormatException: For input string: ""

我正在尝试仅使用注释、java、JSP、spring data、spring mvc 和 mongo db 构建一个 Web 应用程序。

我的大部分工作都正常,但是当我尝试创建具有多选列表的 JSP 表单时,我收到标题错误。

我正在尝试创建一个代理对象并将其保存到 mongodb 数据库。多选框正在传回所选对象的字符串 ID。代理对象具有需要用多选列表填充的列表。

以下是 Chrome 开发工具的响应数据:

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>

这是 Controller 保存请求映射:

@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: For input string: "" 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)

我尝试创建自定义数据绑定(bind)程序,但这没有帮助。

有人可以指导我正确的方法来做这些事情吗?这是我第一次尝试自己制作网络应用程序。

这是代理类:

@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;
}
}

谢谢,马特

最佳答案

Spring 不处理空方括号。总结一下,您可以使用

  • ?myarray[0]=aa&myarray[1]=bb
  • ?myarray=aa&myarray=bb

但不是

  • ?myarray[]=aa&myarray[]=bb

我创建了票 https://jira.springsource.org/browse/SPR-11214

关于java - 请求处理失败;嵌套异常是 java.lang.NumberFormatException : For input string: "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19886373/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com