我使用以下输入标签,其中 entry 是 myMap 的一个条目。
<form:input path="myMap[${entry.key}].parameters[${counter}].value" />
和以下对象
Map<Long, MyViewModel> myMap;
public class MyViewModel {
private List<My2ViewModel> parameters;
...
如果 entry.key 的值为整数,则一切正常。但如果它很长(例如 5000000000)它会崩溃
org.springframework.expression.spel.SpelParseException: EL1035E:(pos 14): The value '5000000000' cannot be parsed as an int
at org.springframework.expression.spel.ast.Literal.getIntLiteral(Literal.java:79)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatLiteral(InternalSpelExpressionParser.java:688)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatStartNode(InternalSpelExpressionParser.java:429)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPrimaryExpression(InternalSpelExpressionParser.java:282)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatUnaryExpression(InternalSpelExpressionParser.java:275)
...
Caused by: java.lang.NumberFormatException: For input string: "5000000000"
当我添加 L(斯蒂芬的建议)时,我得到了另一个错误。
<form:input path="myMap[${entry.key}L].parameters[${counter}].value" />
java.lang.IllegalArgumentException: The field type is required
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48)
at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:277)
at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
...