選択ボックスのデータをスプリングコントローラーに投稿しているときに問題が発生しました。
<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'
もう1つの選択ボックスがあり、両方のコードは(ほぼ)同じです。それでも、春がこれをStringではなくString[]として扱う理由はわかりません。誰かがこれに光を当てることができますか?