My favorites | Sign in
Project Logo
                
Search
for
Updated Feb 25, 2009 by kuisong.tong
DTO  
DTO conversion automaticcally

Introduction

We need Data Transfer Object to pass object between presentation and business layers, or between remoting invocation. We use Dozer and @Delegator to do this for us.

Setup

First, we need config the bean mapping file location:

	<bean class="cn.muthos.polyforms.conversion.BeanMappingFile">
		<constructor-arg value="bean-mappings.xml" />
	</bean>

Then, we add the bean-mappings.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
    "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
<mappings>
	<configuration>
		<stop-on-errors>true</stop-on-errors>
		<date-format>MM/dd/yyyy HH:mm:ss</date-format>
		<wildcard>true</wildcard>
		<trim-strings>false</trim-strings>
	</configuration>
</mappings>

Details

We also need add converter for conversion between entity identity and entity in bean-mappings.xml.

		<custom-converters>
			<converter type="cn.muthos.polyforms.conversion.dozer.EntityConverter">
				<class-a>java.lang.String</class-a>
				<class-b>cn.muthos.polyforms.sample.domain.User</class-b>
			</converter>
		</custom-converters>


Sign in to add a comment
Hosted by Google Code