没有合适的资源?快使用搜索试试~ 我知道了~
首页spring MVC数据绑定大全
spring MVC数据绑定 含例子 转载自疯芒毕露的专栏 刚开始用spring mvc 做web开发时 经常会不知道如何合适绑定页面数据 用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便 本人最开始也是这么认为 经过一段时间的应用和测试 总结出以下几种情况 希望对刚接触spring mvc 的朋友有所帮助 ">spring MVC数据绑定 含例子 转载自疯芒毕露的专栏 刚开始用spring mvc 做web开发时 经常会不知道如何合适绑定页面数据 用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便 本人最开始也是这么认为 经过一段时间的应用和测试 [更多]
资源详情
资源评论
资源推荐

Spring MVC
数据绑定大全
分类:Sun JAVA2010-10-07 21:246591 人阅读评论(2)收藏举报
springmvcclassinputuserstring
刚开始用 spring mvc 做 web 开发时,经常会不知道如何合适绑定页面数据.用惯 struts2 的朋
友更认为 spring mvc 绑定数据不如 struts2 方便(本人最开始也是这么认为),经过一段时间
的应用和测试,总结出以下几种情况,希望对刚接触 spring mvc 的朋友有所帮助.
示例程序下载
查看 spring 源码可以看出 spring 支持转换的数据类型已经很多了.
org.springframework.beans.PropertyEditorRegistrySupport.java
[java]view plaincopy
1. /**
2. *Actuallyregisterthedefaulteditorsforthisregistryinstanc
e.
3. */
4. privatevoiddoRegisterDefaultEditors(){
5. this.defaultEditors=newHashMap<Class,PropertyEditor>(64);
6. //Simpleeditors,withoutparameterizationcapabilities.
7. //TheJDKdoesnotcontainadefaulteditorforanyofthese
targettypes.
8. this.defaultEditors.put(Charset.class,newCharsetEditor());
9. this.defaultEditors.put(Class.class,newClassEditor());
10. this.defaultEditors.put(Class[].class,newClassArrayEditor())
;
11. this.defaultEditors.put(Currency.class,newCurrencyEditor());
12. this.defaultEditors.put(File.class,newFileEditor());
13. this.defaultEditors.put(InputStream.class,newInputStreamEdit
or());
14. this.defaultEditors.put(Locale.class,newLocaleEditor());
15. this.defaultEditors.put(Pattern.class,newPatternEditor());
16. this.defaultEditors.put(Properties.class,newPropertiesEditor
());

17. this.defaultEditors.put(Resource[].class,newResourceArrayPro
pertyEditor());
18. this.defaultEditors.put(TimeZone.class,newTimeZoneEditor());
19. this.defaultEditors.put(URI.class,newURIEditor());
20. this.defaultEditors.put(URL.class,newURLEditor());
21. //Defaultinstancesofcollectioneditors.
22. //Canbeoverriddenbyregisteringcustominstancesofthose
ascustomeditors.
23. this.defaultEditors.put(Collection.class,newCustomCollection
Editor(Collection.class));
24. this.defaultEditors.put(Set.class,newCustomCollectionEditor(
Set.class));
25. this.defaultEditors.put(SortedSet.class,newCustomCollectionE
ditor(SortedSet.class));
26. this.defaultEditors.put(List.class,newCustomCollectionEditor
(List.class));
27. this.defaultEditors.put(SortedMap.class,newCustomMapEditor(S
ortedMap.class));
28. //Defaulteditorsforprimitivearrays.
29. this.defaultEditors.put(byte[].class,newByteArrayPropertyEdi
tor());
30. this.defaultEditors.put(char[].class,newCharArrayPropertyEdi
tor());
31. //TheJDKdoesnotcontainadefaulteditorforchar!
32. this.defaultEditors.put(char.class,newCharacterEditor(false)
);
33. this.defaultEditors.put(Character.class,newCharacterEditor(t
rue));
34. //Spring'sCustomBooleanEditoracceptsmoreflagvaluesthan
theJDK'sdefaulteditor.
35. this.defaultEditors.put(boolean.class,newCustomBooleanEditor
(false));
36. this.defaultEditors.put(Boolean.class,newCustomBooleanEditor
(true));
37. //TheJDKdoesnotcontaindefaulteditorsfornumberwrapper
types!
38. //OverrideJDKprimitivenumbereditorswithourownCustomNu
mberEditor.
39. this.defaultEditors.put(byte.class,newCustomNumberEditor(Byt
e.class,false));
40. this.defaultEditors.put(Byte.class,newCustomNumberEditor(Byt
e.class,true));

41. this.defaultEditors.put(short.class,newCustomNumberEditor(Sh
ort.class,false));
42. this.defaultEditors.put(Short.class,newCustomNumberEditor(Sh
ort.class,true));
43. this.defaultEditors.put(int.class,newCustomNumberEditor(Inte
ger.class,false));
44. this.defaultEditors.put(Integer.class,newCustomNumberEditor(
Integer.class,true));
45. this.defaultEditors.put(long.class,newCustomNumberEditor(Lon
g.class,false));
46. this.defaultEditors.put(Long.class,newCustomNumberEditor(Lon
g.class,true));
47. this.defaultEditors.put(float.class,newCustomNumberEditor(Fl
oat.class,false));
48. this.defaultEditors.put(Float.class,newCustomNumberEditor(Fl
oat.class,true));
49. this.defaultEditors.put(double.class,newCustomNumberEditor(D
ouble.class,false));
50. this.defaultEditors.put(Double.class,newCustomNumberEditor(D
ouble.class,true));
51. this.defaultEditors.put(BigDecimal.class,newCustomNumberEdit
or(BigDecimal.class,true));
52. this.defaultEditors.put(BigInteger.class,newCustomNumberEdit
or(BigInteger.class,true));
53. //Onlyregisterconfigvalueeditorsifexplicitlyrequested.
54. if(this.configValueEditorsActive){
55. StringArrayPropertyEditorsae=newStringArrayPropertyEdi
tor();
56. this.defaultEditors.put(String[].class,sae);
57. this.defaultEditors.put(short[].class,sae);
58. this.defaultEditors.put(int[].class,sae);
59. this.defaultEditors.put(long[].class,sae);
60. }
61. }
1.基本数据类型
很简单,该怎么写就怎么写.
剩余13页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1