君子博学而日参省乎己 则知明而行无过矣

博客园 首页 新随笔 联系 订阅 管理

2012年5月16日 #

摘要: 延迟加载过滤器Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时,由于加载领域对象的 Hibernate Session 已经关闭,这些导致延迟加载数据的访问异常。Spring 为此专门提供了一个 OpenSessionInViewFilter 过滤器,它的主要功能是使每个请求过程绑定一个 Hibernate Session,即使最初的事务已经完成了,也可以在 Web 层进行延迟加载的 阅读全文
posted @ 2012-05-16 21:02 刺猬的温驯 阅读(463) 评论(0) 推荐(0) 编辑

摘要: 1、通过继承JDK 中的 java.beans.PropertyEditorSupport类来实现自己的编辑器类,该类用于实现将String 类型转换成您需要的数据类型。然后我们只需要在Spring 的容器中对这个编辑器进行有效的“注册”便可以实现Spring 在装配Bean 时自动的将String 类型转换成我们自定义的类型。如何编辑自己的PropertyEditor,其实需要了解一点java.beans包的知识,在该包中,有一个 java.beans.PropertyEditor的接口,它定义了一套接口方法(12个),即通过这些方法如何将一个String变成内部的一个对 象,这两个方法是比 阅读全文
posted @ 2012-05-16 20:58 刺猬的温驯 阅读(1106) 评论(0) 推荐(0) 编辑

摘要: Java代码publicclassPerson{privateStringname;privateintid;privateintage;publicintgetAge(){returnage;}publicvoidsetAge(intage){this.age=age;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}}importjava.beans.Pro 阅读全文
posted @ 2012-05-16 20:57 刺猬的温驯 阅读(3793) 评论(0) 推荐(0) 编辑

摘要: 基于spring-framework-3.1.1.RELEASE7.1、简介在编写可视化界面项目时,我们通常需要对数据进行类型转换、验证及格式化。一、在Spring3之前,我们使用如下架构进行类型转换、验证及格式化:流程:①:类型转换:首先调用PropertyEditor的setAsText(String),内部根据需要调用setValue(Object)方法进行设置转换后的值;②:数据验证:需要显示调用Spring的Validator接口实现进行数据验证;③:格式化显示:需要调用PropertyEditor的getText进行格式化显示。使用如上架构的缺点是:(1、PropertyEdito 阅读全文
posted @ 2012-05-16 20:05 刺猬的温驯 阅读(6776) 评论(0) 推荐(0) 编辑

摘要: Spring mvc处理json需要使用jackson的类库,因此为支持json格式的输入输出需要先修改pom.xml增加jackson包的引用Xml代码<!--json--><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-core-lgpl</artifactId><version>1.8.1</version></dependency><dependency><groupI 阅读全文
posted @ 2012-05-16 19:52 刺猬的温驯 阅读(561) 评论(0) 推荐(0) 编辑

摘要: Spring mvc 目前支持5个tag,分别是mvc:annotation-driven,mvc:interceptors,mvc:view-controller, mvc:resources和mvc:default-servlet-handlermvc:annotation-driven 注册 DefaultAnnotationHandlerMapping 和AnnotationMethodHandlerAdapter两个bean,及一系列缺省的messageconverter(需要classpath中有相应的lib包的支持。)相当于以下配置的效果。Xml代码<beanclass=& 阅读全文
posted @ 2012-05-16 19:49 刺猬的温驯 阅读(322) 评论(0) 推荐(0) 编辑

摘要: Customizing WebDataBinder initializationTo customize request parameter binding with PropertyEditors, etc. via Spring's WebDataBinder, you can either use @InitBinder-annotated methods within your controller or externalize your configuration by providing a custom WebBindingInitializer.Customizing 阅读全文
posted @ 2012-05-16 19:39 刺猬的温驯 阅读(326) 评论(0) 推荐(0) 编辑

摘要: Servlet中的输入参数为都是string类型,而spring mvc通过data bind机制将这些string 类型的输入参数转换为相应的command object(根据view和controller之间传输数据的具体逻辑,也可称为model attributes, domain model objects)。在这个转换过程中,spring实际是先利用java.beans.PropertyEditor中的 setAdText方法来把string格式的输入转换为bean属性,亦可通过继承java.beans.PropertyEditorSupport来实现自定义的PropertyEdit 阅读全文
posted @ 2012-05-16 19:30 刺猬的温驯 阅读(436) 评论(0) 推荐(0) 编辑

摘要: @InitBinderpublicvoidinitBinder(WebDataBinderbinder){SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd");dateFormat.setLenient(false);binder.registerCustomEditor(Date.class,newCustomDateEditor(dateFormat,true));binder.registerCustomEditor(SystemInfo.class,newPropertyEditorSupport( 阅读全文
posted @ 2012-05-16 19:28 刺猬的温驯 阅读(485) 评论(0) 推荐(0) 编辑

摘要: [java]view plaincopymodel对象:User.java:[java]view plaincopypublicclassUser{privateintid;privateStringname;//0:男,1:女,页面上表现为radiobuttonprivateintgender;privateintage;//0:没毕业,1:已经毕业,页面上表现为checkboxprivateintgraduted;//0:没结婚,1:已经结婚,页面上表现为checkboxprivateintmarried;}form表单:<form:form id="user" 阅读全文
posted @ 2012-05-16 19:27 刺猬的温驯 阅读(3700) 评论(0) 推荐(0) 编辑

摘要: 今天碰到一个问题,页面表单上是一个id,但在表单控制器的command里是一个javabean,如果将一个String转换成javabean呢?因为已经有了一个服务于hibernate的javabean,我可不想再写一个javabean,然后再笨笨的转换。在查看SimpleFormController的API的时候,发现它有一个来自父类BaseCommandController的方法——initBinder:BaseCommandController (Spring Framework)initBinderprotected void initBinder(HttpServletRequest 阅读全文
posted @ 2012-05-16 19:26 刺猬的温驯 阅读(462) 评论(0) 推荐(0) 编辑

摘要: Cygwin is a Unix-like environment for windows.It can be obtained from:www.cygwin.comBelow are notes on how to install and setup cygwin for access to group computers.Installation Notes:Download setup.exefromwww.cygwin.com.Run application from your local harddrive.Chose next on first screen.Select &qu 阅读全文
posted @ 2012-05-16 02:57 刺猬的温驯 阅读(387) 评论(0) 推荐(0) 编辑