Spring 表格:"Type [java.lang.String] is not valid for option items"

Spring forms: "Type [java.lang.String] is not valid for option items"

我有一个旧的 MVC 应用程序。

它有一个控制器,方法如下:

@RequestMapping(method=RequestMethod.GET)
public ModelAndView handleGet(@RequestParam(value="userId") String userId){
    ModelMap model = new ModelMap();
    List<Long> relatedIds = getListOfIds(userId)
    RelatedIdFormHolder();
    formHolder.setRelatedIds(relatedIds);
    model.put("relatedIdFormHolder", formHolder);
    return new ModelAndView("relatedIds.jsp", model);
}

我有一个 .jsp 格式如下:

<form:form method="post" commandName="relatedIdFormHolder" id="relatedIdFormHolder" onsubmit="submit_form()">
    <form:select path="selectedId">
        <form:options items="relatedIds"></form:options>
    </form:select>
</form:form>

我有一个像这样的 POJO:

public class RelatedIdFormHolder {

    public List<Long> getRelatedIds() {
        return relatedIds;
    }
    public void setRelatedIds(List<Long> relatedIds) {
        this.relatedIds = relatedIds;
    }
    public String getSelectedId() {
        return selectedId;
    }
    public void setSelectedId(String selectedId) {
        this.selectedId = selectedId;
    }
    List<Long> relatedIds;
    String selectedId; 
}

我访问了正确的 URL,并映射到正确的控制器,然后映射到正确的 .jsp,但是 JSP 在渲染时抛出错误:

ERROR: error500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items

我试过将 relatedIds 和 selectedID 作为字符串和 Longs 在视图中来回传递,但遇到了同样的问题。

什么给的,这应该是直截了当的,我错过了什么?

我想你的表格应该是这样的

<form:option items="${formHandler.relatedIds}"></form:option>

请记住,您需要 ${}