added code for mapstruct tutorial
This commit is contained in:
@@ -5,6 +5,7 @@ public class EmployeeDTO {
|
||||
private int employeeId;
|
||||
private String employeeName;
|
||||
private DivisionDTO division;
|
||||
private String employeeStartDt;
|
||||
|
||||
public int getEmployeeId() {
|
||||
return employeeId;
|
||||
@@ -30,4 +31,12 @@ public class EmployeeDTO {
|
||||
this.division = division;
|
||||
}
|
||||
|
||||
public String getEmployeeStartDt() {
|
||||
return employeeStartDt;
|
||||
}
|
||||
|
||||
public void setEmployeeStartDt(String employeeStartDt) {
|
||||
this.employeeStartDt = employeeStartDt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package org.baeldung.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private Division division;
|
||||
private Date startDt;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@@ -30,4 +33,12 @@ public class Employee {
|
||||
this.division = division;
|
||||
}
|
||||
|
||||
public Date getStartDt() {
|
||||
return startDt;
|
||||
}
|
||||
|
||||
public void setStartDt(Date startDt) {
|
||||
this.startDt = startDt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.baeldung.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.dto.DivisionDTO;
|
||||
import org.baeldung.dto.EmployeeDTO;
|
||||
import org.baeldung.entity.Division;
|
||||
@@ -11,14 +13,22 @@ import org.mapstruct.Mappings;
|
||||
@Mapper
|
||||
public interface EmployeeMapper {
|
||||
|
||||
@Mappings({ @Mapping(target = "employeeId", source = "entity.id"), @Mapping(target = "employeeName", source = "entity.name") })
|
||||
@Mappings({ @Mapping(target = "employeeId", source = "entity.id"),
|
||||
@Mapping(target = "employeeName", source = "entity.name"),
|
||||
@Mapping(target = "employeeStartDt",source = "entity.startDt", dateFormat = "dd-MM-yyyy HH:mm:ss")})
|
||||
EmployeeDTO employeeToEmployeeDTO(Employee entity);
|
||||
|
||||
@Mappings({ @Mapping(target = "id", source = "dto.employeeId"), @Mapping(target = "name", source = "dto.employeeName") })
|
||||
@Mappings({ @Mapping(target = "id", source = "dto.employeeId"),
|
||||
@Mapping(target = "name", source = "dto.employeeName"),
|
||||
@Mapping(target = "startDt",source = "dto.employeeStartDt", dateFormat = "dd-MM-yyyy HH:mm:ss")})
|
||||
Employee employeeDTOtoEmployee(EmployeeDTO dto);
|
||||
|
||||
DivisionDTO divisionToDivisionDTO(Division entity);
|
||||
|
||||
Division divisionDTOtoDivision(DivisionDTO dto);
|
||||
|
||||
List<Employee> convertEmployeeDTOListToEmployeeList(List<EmployeeDTO> list);
|
||||
|
||||
List<EmployeeDTO> convertEmployeeListToEmployeeDTOList(List<Employee> list);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.baeldung.dto.SimpleSource;
|
||||
import org.baeldung.entity.SimpleDestination;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface SimpleSourceDestinationMapper {
|
||||
|
||||
SimpleDestination sourceToDestination(SimpleSource source);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.baeldung.mapper;
|
||||
|
||||
import org.baeldung.dto.SimpleSource;
|
||||
import org.baeldung.entity.SimpleDestination;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface SimpleSourceDestinationSpringMapper {
|
||||
|
||||
SimpleDestination sourceToDestination(SimpleSource source);
|
||||
|
||||
SimpleSource destinationToSource(SimpleDestination destination);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user