springmvc二十:数据绑定
生活随笔
收集整理的這篇文章主要介紹了
springmvc二十:数据绑定
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數據綁定思想和原理
? ? javaBean要和頁面提交的數據一一綁定。 頁面提交的所有數據都是字符串。
?
?牽扯到的問題:
? ? 1).數據綁定期間的數據類型轉換? ? 比如 String-->Integer, ? String--->boolean
? ? 2).數據綁定期間的數據格式化問題.
?? ?3).數據校驗問題, 頁面提交的數據必須要合法. ?前端校驗(js+正則表達式), ?后端校驗(重要數據不僅前端要校驗,后端也要校驗)
?
WebDataBinder: 數據綁定器負責數據綁定工作。
??數據綁定期間產生的類型轉換,格式化,數據校驗等問題
ConversionService組件:負責數據類型的轉換和格式化問題。
ConversionService converters =@org.springframework.format.annotation.DateTimeFormat java.lang.Long -> java.lang.String: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896,@org.springframework.format.annotation.NumberFormat java.lang.Long -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.DateTimeFormat java.util.Calendar -> java.lang.String: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896@org.springframework.format.annotation.DateTimeFormat java.util.Date -> java.lang.String: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896@org.springframework.format.annotation.NumberFormat java.lang.Byte -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.lang.Double -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.lang.Float -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.lang.Integer -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.lang.Short -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.math.BigDecimal -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605c@org.springframework.format.annotation.NumberFormat java.math.BigInteger -> java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.Boolean -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@693a1324java.lang.Character -> java.lang.Number : org.springframework.core.convert.support.CharacterToNumberFactory@19d2052bjava.lang.Character -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@13dc8ea3java.lang.Enum -> java.lang.Integer : org.springframework.core.convert.support.EnumToIntegerConverter@5d23fab3java.lang.Enum -> java.lang.String : org.springframework.core.convert.support.EnumToStringConverter@5f18cd5java.lang.Integer -> java.lang.Enum : org.springframework.core.convert.support.IntegerToEnumConverterFactory@3554f6ffjava.lang.Long -> java.util.Calendar : org.springframework.format.datetime.DateFormatterRegistrar$LongToCalendarConverter@75dc818djava.lang.Long -> java.util.Date : org.springframework.format.datetime.DateFormatterRegistrar$LongToDateConverter@423252d6java.lang.Number -> java.lang.Character : org.springframework.core.convert.support.NumberToCharacterConverter@75187984java.lang.Number -> java.lang.Number : org.springframework.core.convert.support.NumberToNumberConverterFactory@9dd0fe7java.lang.Number -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@1b1c7295java.lang.String -> @org.springframework.format.annotation.DateTimeFormat java.lang.Long: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896,java.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Long: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.DateTimeFormat java.util.Calendar: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896java.lang.String -> @org.springframework.format.annotation.DateTimeFormat java.util.Date: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@1c727896java.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Byte: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Double: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Float: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Integer: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.lang.Short: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.math.BigDecimal: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> @org.springframework.format.annotation.NumberFormat java.math.BigInteger: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@7de4605cjava.lang.String -> java.lang.Boolean : org.springframework.core.convert.support.StringToBooleanConverter@2b51574bjava.lang.String -> java.lang.Character : org.springframework.core.convert.support.StringToCharacterConverter@68a6a21ajava.lang.String -> java.lang.Enum : org.springframework.core.convert.support.StringToEnumConverterFactory@63bed674java.lang.String -> java.lang.Number : org.springframework.core.convert.support.StringToNumberConverterFactory@103f0bc0java.lang.String -> java.nio.charset.Charset : org.springframework.core.convert.support.StringToCharsetConverter@3c4568f8java.lang.String -> java.util.Currency : org.springframework.core.convert.support.StringToCurrencyConverter@3e5d8e63java.lang.String -> java.util.Locale : org.springframework.core.convert.support.StringToLocaleConverter@65202d8ajava.lang.String -> java.util.Properties : org.springframework.core.convert.support.StringToPropertiesConverter@274b8c21java.lang.String -> java.util.UUID : org.springframework.core.convert.support.StringToUUIDConverter@549f9afbjava.nio.charset.Charset -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@70ee90b1java.util.Calendar -> java.lang.Long : org.springframework.format.datetime.DateFormatterRegistrar$CalendarToLongConverter@5388ebd2java.util.Calendar -> java.util.Date : org.springframework.format.datetime.DateFormatterRegistrar$CalendarToDateConverter@ec5aba9java.util.Currency -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@702f2591java.util.Date -> java.lang.Long : org.springframework.format.datetime.DateFormatterRegistrar$DateToLongConverter@1f4ace71java.util.Date -> java.util.Calendar : org.springframework.format.datetime.DateFormatterRegistrar$DateToCalendarConverter@68376cc3java.util.Locale -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@238df2e4java.util.Properties -> java.lang.String : org.springframework.core.convert.support.PropertiesToStringConverter@50dcdeaejava.util.UUID -> java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@3a780024org.springframework.core.convert.support.ArrayToArrayConverter@75ba3523org.springframework.core.convert.support.ArrayToCollectionConverter@1c515979org.springframework.core.convert.support.ArrayToObjectConverter@1af6a711org.springframework.core.convert.support.ArrayToStringConverter@5b8425b7org.springframework.core.convert.support.ByteBufferConverter@67446579org.springframework.core.convert.support.ByteBufferConverter@67446579org.springframework.core.convert.support.ByteBufferConverter@67446579org.springframework.core.convert.support.ByteBufferConverter@67446579org.springframework.core.convert.support.CollectionToArrayConverter@20c92575org.springframework.core.convert.support.CollectionToCollectionConverter@13f6c937org.springframework.core.convert.support.CollectionToObjectConverter@1af1bd6org.springframework.core.convert.support.CollectionToStringConverter@7fcf16acorg.springframework.core.convert.support.FallbackObjectToStringConverter@34adcae8org.springframework.core.convert.support.IdToEntityConverter@3b621fe6,org.springframework.core.convert.support.ObjectToObjectConverter@271c537forg.springframework.core.convert.support.MapToMapConverter@2f14441eorg.springframework.core.convert.support.ObjectToArrayConverter@37525aeborg.springframework.core.convert.support.ObjectToCollectionConverter@f4c7f77org.springframework.core.convert.support.StringToArrayConverter@40c84051org.springframework.core.convert.support.StringToCollectionConverter@74d9b7c1validators負責數據校驗
?
bindingResult負責保存以及解析數據綁定期間數據校驗產生的錯誤。
?
總結
以上是生活随笔為你收集整理的springmvc二十:数据绑定的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springmvc十九:springmv
- 下一篇: springmvc二十一:自定义类型转换