0

我在将选择框数据发布到弹簧控制器时遇到问题。

<form:select path="ContactInfoVO[0].cityId" multiple="single" id="city" class="validate[required] small">       
    <form:option value="-1" label="-- Select City--"></form:option>                     
    <c:forEach var="city" items="${ManagerVO.ContactInfoVO[0].cityList}" varStatus="item">
    <form:option value="${city.cityId}" label="${city.cityName}"/>
</c:forEach> 
</form:select>

Spring 的通用转换服务是在实际值之前添加“,”。查看日志我看到以下内容 -

    23:00:45,511 DEBUG BeanWrapperImpl:579 - Using cached nested BeanWrapper for property 'restaurantContactInfoVO[0]'
23:00:45,512 DEBUG GenericConversionService:139 - Checking if I can convert java.lang.String[] to java.lang.String
23:00:45,516 DEBUG GenericConversionService:358 - Searching for converters indexed by sourceType [[Ljava.lang.String;]
23:00:45,517 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.String]
23:00:45,519 DEBUG GenericConversionService:429 - and indexed by targetType [java.io.Serializable]
23:00:45,520 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.Comparable]
23:00:45,521 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.CharSequence]
23:00:45,523 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.Object]
23:00:45,524 DEBUG GenericConversionService:358 - Searching for converters indexed by sourceType [[Ljava.lang.Object;]
23:00:45,527 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.String]
23:00:45,528 DEBUG GenericConversionService:473 - Found matchable converters org.springframework.core.convert.support.ArrayToStringConverter@ba3bff5
23:00:45,530 DEBUG GenericConversionService:560 - Matching org.springframework.core.convert.support.ArrayToStringConverter@ba3bff5
23:00:45,531 DEBUG GenericConversionService:139 - Checking if I can convert java.lang.String to java.lang.String
23:00:45,532 DEBUG GenericConversionService:246 - Matched cached converter org.springframework.core.convert.support.ObjectToStringConverter@6f69b66e
23:00:45,534 DEBUG GenericConversionService:147 - Yes, I can convert
23:00:45,535 DEBUG GenericConversionService:564 - Matched converter org.springframework.core.convert.support.ArrayToStringConverter@ba3bff5
23:00:45,536 DEBUG GenericConversionService:254 - Caching under ConverterCacheKey [sourceType = java.lang.String[], targetType = java.lang.String]
23:00:45,537 DEBUG GenericConversionService:147 - Yes, I can convert
23:00:45,539 DEBUG GenericConversionService:159 - Converting value array<String>['', '145009'] of java.lang.String[] to java.lang.String
23:00:45,542 DEBUG GenericConversionService:246 - Matched cached converter org.springframework.core.convert.support.ArrayToStringConverter@ba3bff5
23:00:45,544 DEBUG GenericConversionService:159 - Converting value '' of java.lang.String to java.lang.String
23:00:45,545 DEBUG GenericConversionService:246 - Matched cached converter org.springframework.core.convert.support.ObjectToStringConverter@6f69b66e
23:00:45,546 DEBUG GenericConversionService:186 - Converted to ''
23:00:45,548 DEBUG GenericConversionService:159 - Converting value '145009' of java.lang.String to java.lang.String
23:00:45,551 DEBUG GenericConversionService:246 - Matched cached converter org.springframework.core.convert.support.ObjectToStringConverter@6f69b66e
23:00:45,552 DEBUG GenericConversionService:186 - Converted to '145009'
23:00:45,554 DEBUG GenericConversionService:186 - Converted to ',145009'

我还有一个选择框,两者的代码都是相同的(几乎)。我仍然不知道为什么 spring 将其视为 String [] 而不是 String。有人可以对此有所了解吗?

4

1 回答 1

0

表单上有另一个具有相同 id 的参数导致此问题。现在修好了。

于 2012-10-16T04:12:08.200 回答