Spring Freemarker:创建下拉字段,并从Map';s键/值

Spring Freemarker:创建下拉字段,并从Map';s键/值,spring,spring-mvc,freemarker,Spring,Spring Mvc,Freemarker,如何在freemarker模板中创建下拉字段?下拉选项和值将从映射中传递。这是从控制器传递的映射: Map<String, Map<String, String>> codeTable = new HashMap<String,Map<String, String>>(); Map<String, String> codeTableValues = new HashMap<String,String>();

如何在freemarker模板中创建下拉字段?下拉选项和值将从映射中传递。这是从控制器传递的映射:

Map<String, Map<String, String>> codeTable = new HashMap<String,Map<String, String>>();
Map<String, String> codeTableValues = new HashMap<String,String>();
        codeTableValues.put("1", "US");
        codeTableValues.put("2", "UK");
        codeTableValues.put("3", "India");
        codeTableValues.put("4", "Ireland");
        codeTableValues.put("5", "Germany");
        codeTable.put("country", codeTableValues);
例外情况

FreeMarker template error: Method public org.springframework.web.servlet.support.BindStatus org.springframework.web.servlet.support.RequestContext.getBindStatus(java.lang.String) throws java.lang.IllegalStateException threw an exception when invoked on org.springframework.web.servlet.support.RequestContext object "org.springframework.web.servlet.support.RequestContext@1479ef9" with arguments of types [java.lang.String,]. See cause exception. The failing instruction (FTL stack trace): ---------- ==> #assign status = springMacroRequestCo... [in template "spring.ftl" in macro "bind" at line 74, column 17] #else [in template "spring.ftl" in macro "bind" at line 73, column 9] @spring.bind "codeTable.country" [in template "index.ftl" at line 31, column 33] #elseif field.@type = "select" [in template "index.ftl" at line 30, column 25]

如果你想增加你得到答案的机会,你应该复制粘贴错误信息而不丢失所有的换行符。另外,失败的是
@spring.bind
(因此您的问题可能会更具体),但您还没有包括原因异常。感谢您的回复。我明白了
选项
失败的原因。但我找不到任何使用Map创建下拉字段的示例。你能帮我解决这个问题吗?另外,我找到的唯一的spring.formSingleSelect实现就是这个SO问题。我不是spring用户,我只知道FreeMarker。查看
spring.ftl
我看到第二个参数是
Map
。因此,如果您传入的是一个
映射
,它应该可以工作。那么现在的错误消息是什么呢?我们将在周一尝试并让您知道。
FreeMarker template error: Method public org.springframework.web.servlet.support.BindStatus org.springframework.web.servlet.support.RequestContext.getBindStatus(java.lang.String) throws java.lang.IllegalStateException threw an exception when invoked on org.springframework.web.servlet.support.RequestContext object "org.springframework.web.servlet.support.RequestContext@1479ef9" with arguments of types [java.lang.String,]. See cause exception. The failing instruction (FTL stack trace): ---------- ==> #assign status = springMacroRequestCo... [in template "spring.ftl" in macro "bind" at line 74, column 17] #else [in template "spring.ftl" in macro "bind" at line 73, column 9] @spring.bind "codeTable.country" [in template "index.ftl" at line 31, column 33] #elseif field.@type = "select" [in template "index.ftl" at line 30, column 25]