1、spring注入dozer
applicationContext.xml
<!--dozer-->
<import resource="dozer.xml"/>
2.dozer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-autowire="byName" default-lazy-init="false">
<bean id="mapper" class="org.dozer.spring.DozerBeanMapperFactoryBean">
<property name="mappingFiles">
<list>
<value>classpath*:dozer/dozer-mapping.xml</value>
</list>
</property>
</bean>
</beans>
3、dozer-mapping.xml
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping date-format="yyyy-MM-dd">
<class-a>cn.swifthealth.api_write.model.ComPatientInfoVo</class-a>
<class-b>cn.swifthealth.api_write.model.ComPatientInfo</class-b>
<field>
<a>eDate</a>
<b>end_date</b>
</field>
</mapping>
<mapping>
<class-a>cn.swifthealth.api.common.patient.PatVisitRecord</class-a>
<class-b>cn.swifthealth.api_write.model.ComPatientInfo</class-b>
<field>
<a>id</a>
<b>card_No</b>
</field>
<field>
<a>patUserId</a>
<b>prof_Code</b>
</field>
<--对于直接能映射的,使用xml,不能的话,使用api,注入到mapping-->
<field custom-converter="cn.swifthealth.api_write.model.ComPatientInfoConverter">
<a>clinicType</a>
<b>work_Home</b>
</field>
</mapping>
</mappings>
4.对于直接能映射的,使用xml,不能的话,使用api,注入到mapping
public class ComPatientInfoConverter implements CustomConverter{
public String convert(Object destination, Object source,
Class destClass, Class sourceClass) {
if (source == null) {
return null;
}
String dest = null;
if (source instanceof OType) {
// check to see if the object already exists
if ("已退款".equals(((OType) source).getName())) {
dest = "0";
} else {
dest = "1";
}
}
return dest;
}
}
applicationContext.xml
<!--dozer-->
<import resource="dozer.xml"/>
2.dozer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-autowire="byName" default-lazy-init="false">
<bean id="mapper" class="org.dozer.spring.DozerBeanMapperFactoryBean">
<property name="mappingFiles">
<list>
<value>classpath*:dozer/dozer-mapping.xml</value>
</list>
</property>
</bean>
</beans>
3、dozer-mapping.xml
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping date-format="yyyy-MM-dd">
<class-a>cn.swifthealth.api_write.model.ComPatientInfoVo</class-a>
<class-b>cn.swifthealth.api_write.model.ComPatientInfo</class-b>
<field>
<a>eDate</a>
<b>end_date</b>
</field>
</mapping>
<mapping>
<class-a>cn.swifthealth.api.common.patient.PatVisitRecord</class-a>
<class-b>cn.swifthealth.api_write.model.ComPatientInfo</class-b>
<field>
<a>id</a>
<b>card_No</b>
</field>
<field>
<a>patUserId</a>
<b>prof_Code</b>
</field>
<--对于直接能映射的,使用xml,不能的话,使用api,注入到mapping-->
<field custom-converter="cn.swifthealth.api_write.model.ComPatientInfoConverter">
<a>clinicType</a>
<b>work_Home</b>
</field>
</mapping>
</mappings>
4.对于直接能映射的,使用xml,不能的话,使用api,注入到mapping
public class ComPatientInfoConverter implements CustomConverter{
public String convert(Object destination, Object source,
Class destClass, Class sourceClass) {
if (source == null) {
return null;
}
String dest = null;
if (source instanceof OType) {
// check to see if the object already exists
if ("已退款".equals(((OType) source).getName())) {
dest = "0";
} else {
dest = "1";
}
}
return dest;
}
}