您可以通过这种方式注册自定义转换器:
import org.springframework.core.convert.converter.Converter;
class UUIDConverter implements Converter<String, UUID> {
@Override
public UUID convert(String source) {
return UUID.fromString(source);
}
}
并使用 Spring MVC 注册它:
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="....UUIDConverter"/>
</set>
</property>
</bean>
<mvc:annotation-driven conversion-service="conversionService">
</mvc:annotation-driven>
现在,如果您提交 UUID,它应该会正确映射到列表。