added persistence
This commit is contained in:
42
mapstruct/src/main/java/org/baeldung/dto/EmployeeDTO.java
Normal file
42
mapstruct/src/main/java/org/baeldung/dto/EmployeeDTO.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.baeldung.dto;
|
||||
|
||||
public class EmployeeDTO {
|
||||
|
||||
private int employeeId;
|
||||
private String employeeName;
|
||||
private int divisionId;
|
||||
private String divisionName;
|
||||
|
||||
public int getEmployeeId() {
|
||||
return employeeId;
|
||||
}
|
||||
|
||||
public void setEmployeeId(int employeeId) {
|
||||
this.employeeId = employeeId;
|
||||
}
|
||||
|
||||
public String getEmployeeName() {
|
||||
return employeeName;
|
||||
}
|
||||
|
||||
public void setEmployeeName(String employeeName) {
|
||||
this.employeeName = employeeName;
|
||||
}
|
||||
|
||||
public int getDivisionId() {
|
||||
return divisionId;
|
||||
}
|
||||
|
||||
public void setDivisionId(int divisionId) {
|
||||
this.divisionId = divisionId;
|
||||
}
|
||||
|
||||
public String getDivisionName() {
|
||||
return divisionName;
|
||||
}
|
||||
|
||||
public void setDivisionName(String divisionName) {
|
||||
this.divisionName = divisionName;
|
||||
}
|
||||
|
||||
}
|
||||
24
mapstruct/src/main/java/org/baeldung/dto/SimpleSource.java
Normal file
24
mapstruct/src/main/java/org/baeldung/dto/SimpleSource.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.baeldung.dto;
|
||||
|
||||
public class SimpleSource {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
33
mapstruct/src/main/java/org/baeldung/entity/Division.java
Normal file
33
mapstruct/src/main/java/org/baeldung/entity/Division.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.entity;
|
||||
|
||||
public class Division {
|
||||
|
||||
public Division() {
|
||||
}
|
||||
|
||||
public Division(int id, String name) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
33
mapstruct/src/main/java/org/baeldung/entity/Employee.java
Normal file
33
mapstruct/src/main/java/org/baeldung/entity/Employee.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.entity;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private Division division;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Division getDivision() {
|
||||
return division;
|
||||
}
|
||||
|
||||
public void setDivision(Division division) {
|
||||
this.division = division;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.baeldung.entity;
|
||||
|
||||
public class SimpleDestination {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.baeldung.mapper;
|
||||
|
||||
import org.baeldung.dto.EmployeeDTO;
|
||||
import org.baeldung.entity.Employee;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
|
||||
@Mapper
|
||||
public interface EmployeeMapper {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target="divisionId",source="entity.division.id"),
|
||||
@Mapping(target="divisionName",source="entity.division.name"),
|
||||
@Mapping(target="employeeId",source="entity.id"),
|
||||
@Mapping(target="employeeName",source="entity.name")
|
||||
})
|
||||
EmployeeDTO employeeToEmployeeDTO(Employee entity);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target="id",source="dto.employeeId"),
|
||||
@Mapping(target="name",source="dto.employeeName"),
|
||||
@Mapping(target="division",expression="java(new org.baeldung.entity.Division(dto.getDivisionId(),dto.getDivisionName()))")
|
||||
})
|
||||
Employee employeeDTOtoEmployee(EmployeeDTO dto);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.baeldung.mapper;
|
||||
|
||||
import org.baeldung.dto.SimpleSource;
|
||||
import org.baeldung.entity.SimpleDestination;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SimpleSourceDestinationMapper {
|
||||
|
||||
SimpleDestination sourceToDestination(SimpleSource source);
|
||||
SimpleSource destinationToSource(SimpleDestination destination);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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