Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用<;表格:选择>;及<;形式:期权>;使用转换器但转换不发生,为什么?_Spring_Spring Mvc - Fatal编程技术网

Spring 使用<;表格:选择>;及<;形式:期权>;使用转换器但转换不发生,为什么?

Spring 使用<;表格:选择>;及<;形式:期权>;使用转换器但转换不发生,为什么?,spring,spring-mvc,Spring,Spring Mvc,我有这个表格用于创建一个扩展: <form:form method="post" action="..." modelAttribute="enrichment"> ... <form:select path="tag"> <form:options items="${tagList}" itemValue="id" itemLabel="label" /> </form:select> ...

我有这个表格用于创建一个
扩展

<form:form method="post" action="..." modelAttribute="enrichment">
    ...
    <form:select path="tag"> 
        <form:options items="${tagList}" itemValue="id" itemLabel="label" />
    </form:select>
    ...
我创建了这个bean:

<bean id="conversionService"
      class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="exemple.IdToTagConverter"/>
        </list>
    </property>
</bean>

我想它会自动转换。但错误信息仍在此处:

[未能将“java.lang.String”类型的属性值转换为 属性“Tag”的必需类型“example.Tag”;嵌套异常为 java.lang.IllegalStateException:无法转换类型的值 [java.lang.String]转换为属性“Tag”所需的类型[example.Tag]: 找不到匹配的编辑器或转换策略]


我错过了什么?

看起来Spring没有意识到您的转换器或转换服务。按照文档的这一部分注册您的自定义转换器->

看起来Spring不知道您的转换器或转换服务。按照文档的这一部分注册自定义转换器->

在此处找到解决方案:

我刚换了

<mvc:annotation-driven />


它成功了。为什么?Spring MVC Voodoo.

在这里找到了解决方案:

我刚换了

<mvc:annotation-driven />


它成功了。为什么?春季MVC巫毒

<mvc:annotation-driven conversion-service="conversionService" />