Dozer:列表的字符串到日期字段级映射
Dozer : String-To-Date Field Level Mapping for a List
我想将 DTO
(都是字符串数据类型)映射到 VO
(包含字符串、整数、布尔值、日期)
学生DTO
private StudentDetailDTO student;
StudentDetailDTO :
private String sid;
private String name;
private String createDt;
private String studentInd;
private List<FeeReceiptDTO> feeDetails;
FeeReceiptDTO:
private String semisterNum;
private String feeAmount;
private String paidOn;
StudentDetailVO :
private int sid;
private String name;
private Date createDt;
private boolean studentInd;
private List<FeeReceiptVO> feeDetails;
费用收据VO:
private int semisterNum;
private Double feeAmount;
private Date paidOn;
我正在使用 DOZZER
将我的 DTO 映射到 VO String-to-Date-DozzerMapping
DozzerMapper.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="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.StudentDTO</class-a>
<class-b>com.college.student.vo.StudentVO</class-b>
<field>
<a>student.sid</a>
<b>sid</b>
</field>
<field>
<a>student.name</a>
<b>name</b>
</field>
<field>
<a>student.createDt</a>
<b>createDt</b>
</field>
<field>
<a>student.studentInd</a>
<b>studentInd</b>
</field>
<field>
<a date-format="MM/dd/yyyy HH:mm">student.feeDetails</a>
<b>feeDetails</b>
</field>
</mapping>
</mappings>
但是,feeDetails 中的日期,即 paidOn
无法从字符串格式化为日期。
我是不是做错了什么?
我需要为这个 paidOn
字段写一个 CustomStringToDateConvertor
吗?
错误日志:
ERROR [org.dozer.MappingProcessor] (http-localhost-127.0.0.1-9090-1) Field mapping error -->
MapId: null
Type: null
Source parent class: com.college.student.dto.StudentDTO
Source field name: paidOn
Source field type: class java.lang.String
Source field value: 01/01/2015 01:01
Dest parent class: com.college.student.vo.StudentVO
Dest field name: paidOn
Dest field type: java.util.Date: org.dozer.converters.ConversionException: Unable to determine time in millis of source object
at org.dozer.converters.DateConverter.convert(DateConverter.java:81) [dozer-5.4.0.jar:]
at org.dozer.converters.PrimitiveOrWrapperConverter.convert(PrimitiveOrWrapperConverter.java:70) [dozer-5.4.0.jar:]
我尝试调试,我发现此日期的 dateFormat
在 Dozzer org.dozer.converters.DateConvertor
的日期转换器中显示为 null
我在 field-level
处定义了 date-format
但它对对象的 List
没有影响。
还有其他方法吗?
因为,Dozer 无法转换 String-To-Date - At Field Level Mapping for a List
。
我为列表定义了一个新映射,即,将其视为 Object
我改了 DozerMapper.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="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.FeeReceiptDTO</class-a>
<class-b>com.college.student.vo.FeeReceiptVO</class-b>
</mapping>
<mapping date-format="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.StudentDTO</class-a>
<class-b>com.college.student.vo.StudentVO</class-b>
<field>
<a>student.sid</a>
<b>sid</b>
</field>
<field>
<a>student.name</a>
<b>name</b>
</field>
<field>
<a>student.createDt</a>
<b>createDt</b>
</field>
<field>
<a>student.studentInd</a>
<b>studentInd</b>
</field>
<field>
<a>student.feeDetails</a>
<b>feeDetails</b>
</field>
</mapping>
</mappings>
我想将 DTO
(都是字符串数据类型)映射到 VO
(包含字符串、整数、布尔值、日期)
学生DTO
private StudentDetailDTO student;
StudentDetailDTO :
private String sid;
private String name;
private String createDt;
private String studentInd;
private List<FeeReceiptDTO> feeDetails;
FeeReceiptDTO:
private String semisterNum;
private String feeAmount;
private String paidOn;
StudentDetailVO :
private int sid;
private String name;
private Date createDt;
private boolean studentInd;
private List<FeeReceiptVO> feeDetails;
费用收据VO:
private int semisterNum;
private Double feeAmount;
private Date paidOn;
我正在使用 DOZZER
将我的 DTO 映射到 VO String-to-Date-DozzerMapping
DozzerMapper.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="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.StudentDTO</class-a>
<class-b>com.college.student.vo.StudentVO</class-b>
<field>
<a>student.sid</a>
<b>sid</b>
</field>
<field>
<a>student.name</a>
<b>name</b>
</field>
<field>
<a>student.createDt</a>
<b>createDt</b>
</field>
<field>
<a>student.studentInd</a>
<b>studentInd</b>
</field>
<field>
<a date-format="MM/dd/yyyy HH:mm">student.feeDetails</a>
<b>feeDetails</b>
</field>
</mapping>
</mappings>
但是,feeDetails 中的日期,即 paidOn
无法从字符串格式化为日期。
我是不是做错了什么?
我需要为这个 paidOn
字段写一个 CustomStringToDateConvertor
吗?
错误日志:
ERROR [org.dozer.MappingProcessor] (http-localhost-127.0.0.1-9090-1) Field mapping error -->
MapId: null
Type: null
Source parent class: com.college.student.dto.StudentDTO
Source field name: paidOn
Source field type: class java.lang.String
Source field value: 01/01/2015 01:01
Dest parent class: com.college.student.vo.StudentVO
Dest field name: paidOn
Dest field type: java.util.Date: org.dozer.converters.ConversionException: Unable to determine time in millis of source object
at org.dozer.converters.DateConverter.convert(DateConverter.java:81) [dozer-5.4.0.jar:]
at org.dozer.converters.PrimitiveOrWrapperConverter.convert(PrimitiveOrWrapperConverter.java:70) [dozer-5.4.0.jar:]
我尝试调试,我发现此日期的 dateFormat
在 Dozzer org.dozer.converters.DateConvertor
null
我在 field-level
处定义了 date-format
但它对对象的 List
没有影响。
还有其他方法吗?
因为,Dozer 无法转换 String-To-Date - At Field Level Mapping for a List
。
我为列表定义了一个新映射,即,将其视为 Object
我改了 DozerMapper.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="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.FeeReceiptDTO</class-a>
<class-b>com.college.student.vo.FeeReceiptVO</class-b>
</mapping>
<mapping date-format="MM/dd/yyyy HH:mm" map-null="true" map-empty-string="true" wildcard="true" type="one-way" >
<class-a>com.college.student.dto.StudentDTO</class-a>
<class-b>com.college.student.vo.StudentVO</class-b>
<field>
<a>student.sid</a>
<b>sid</b>
</field>
<field>
<a>student.name</a>
<b>name</b>
</field>
<field>
<a>student.createDt</a>
<b>createDt</b>
</field>
<field>
<a>student.studentInd</a>
<b>studentInd</b>
</field>
<field>
<a>student.feeDetails</a>
<b>feeDetails</b>
</field>
</mapping>
</mappings>