Skip to content

Commit 638e666

Browse files
authored
Merge pull request eugenp#618 from jesus-dayo/master
added code to mapstruct tutorial
2 parents f99f6d9 + e9925d3 commit 638e666

14 files changed

Lines changed: 395 additions & 210 deletions

‎mapstruct/bin/pom.xml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>mapstruct</artifactId>
7+
<name>mapstruct</name>
8+
<groupId>com.baeldung</groupId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<properties>
13+
<org.mapstruct.version>1.0.0.Final</org.mapstruct.version>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.mapstruct</groupId>
18+
<artifactId>mapstruct-jdk8</artifactId>
19+
<version>${org.mapstruct.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>4.12</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
<build>
29+
<finalName>mapstruct</finalName>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>3.5.1</version>
35+
<configuration>
36+
<source>1.8</source>
37+
<target>1.8</target>
38+
<annotationProcessorPaths>
39+
<path>
40+
<groupId>org.mapstruct</groupId>
41+
<artifactId>mapstruct-processor</artifactId>
42+
<version>${org.mapstruct.version}</version>
43+
</path>
44+
</annotationProcessorPaths>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>

‎mapstruct/pom.xml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
<version>4.12</version>
2525
<scope>test</scope>
2626
</dependency>
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-context</artifactId>
30+
<version>4.3.2.RELEASE</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-test</artifactId>
35+
<version>4.3.2.RELEASE</version>
36+
<scope>test</scope>
37+
</dependency>
2738
</dependencies>
2839
<build>
2940
<finalName>mapstruct</finalName>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.baeldung.dto;
2+
3+
public class DivisionDTO {
4+
5+
public DivisionDTO() {
6+
}
7+
8+
public DivisionDTO(int id, String name) {
9+
super();
10+
this.id = id;
11+
this.name = name;
12+
}
13+
14+
private int id;
15+
private String name;
16+
17+
public int getId() {
18+
return id;
19+
}
20+
21+
public void setId(int id) {
22+
this.id = id;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
}

‎mapstruct/src/main/java/org/baeldung/dto/EmployeeDTO.java‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22

33
public class EmployeeDTO {
44

5-
private int employeeId;
6-
private String employeeName;
7-
private int divisionId;
8-
private String divisionName;
9-
10-
public int getEmployeeId() {
11-
return employeeId;
12-
}
13-
14-
public void setEmployeeId(int employeeId) {
15-
this.employeeId = employeeId;
16-
}
17-
18-
public String getEmployeeName() {
19-
return employeeName;
20-
}
21-
22-
public void setEmployeeName(String employeeName) {
23-
this.employeeName = employeeName;
24-
}
25-
26-
public int getDivisionId() {
27-
return divisionId;
28-
}
29-
30-
public void setDivisionId(int divisionId) {
31-
this.divisionId = divisionId;
32-
}
33-
34-
public String getDivisionName() {
35-
return divisionName;
36-
}
37-
38-
public void setDivisionName(String divisionName) {
39-
this.divisionName = divisionName;
40-
}
5+
private int employeeId;
6+
private String employeeName;
7+
private DivisionDTO division;
8+
private String employeeStartDt;
9+
10+
public int getEmployeeId() {
11+
return employeeId;
12+
}
13+
14+
public void setEmployeeId(int employeeId) {
15+
this.employeeId = employeeId;
16+
}
17+
18+
public String getEmployeeName() {
19+
return employeeName;
20+
}
21+
22+
public void setEmployeeName(String employeeName) {
23+
this.employeeName = employeeName;
24+
}
25+
26+
public DivisionDTO getDivision() {
27+
return division;
28+
}
29+
30+
public void setDivision(DivisionDTO division) {
31+
this.division = division;
32+
}
33+
34+
public String getEmployeeStartDt() {
35+
return employeeStartDt;
36+
}
37+
38+
public void setEmployeeStartDt(String employeeStartDt) {
39+
this.employeeStartDt = employeeStartDt;
40+
}
4141

4242
}

‎mapstruct/src/main/java/org/baeldung/dto/SimpleSource.java‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
public class SimpleSource {
44

5-
private String name;
6-
private String description;
7-
8-
public String getName() {
9-
return name;
10-
}
5+
private String name;
6+
private String description;
117

12-
public void setName(String name) {
13-
this.name = name;
14-
}
8+
public String getName() {
9+
return name;
10+
}
1511

16-
public String getDescription() {
17-
return description;
18-
}
12+
public void setName(String name) {
13+
this.name = name;
14+
}
15+
16+
public String getDescription() {
17+
return description;
18+
}
19+
20+
public void setDescription(String description) {
21+
this.description = description;
22+
}
1923

20-
public void setDescription(String description) {
21-
this.description = description;
22-
}
23-
2424
}

‎mapstruct/src/main/java/org/baeldung/entity/Division.java‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
public class Division {
44

5-
public Division() {
6-
}
5+
public Division() {
6+
}
77

8-
public Division(int id, String name) {
9-
super();
10-
this.id = id;
11-
this.name = name;
12-
}
8+
public Division(int id, String name) {
9+
super();
10+
this.id = id;
11+
this.name = name;
12+
}
1313

14-
private int id;
15-
private String name;
14+
private int id;
15+
private String name;
1616

17-
public int getId() {
18-
return id;
19-
}
17+
public int getId() {
18+
return id;
19+
}
2020

21-
public void setId(int id) {
22-
this.id = id;
23-
}
21+
public void setId(int id) {
22+
this.id = id;
23+
}
2424

25-
public String getName() {
26-
return name;
27-
}
25+
public String getName() {
26+
return name;
27+
}
2828

29-
public void setName(String name) {
30-
this.name = name;
31-
}
29+
public void setName(String name) {
30+
this.name = name;
31+
}
3232

3333
}
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
package org.baeldung.entity;
22

3+
import java.util.Date;
4+
35
public class Employee {
46

5-
private int id;
6-
private String name;
7-
private Division division;
7+
private int id;
8+
private String name;
9+
private Division division;
10+
private Date startDt;
11+
12+
public int getId() {
13+
return id;
14+
}
15+
16+
public void setId(int id) {
17+
this.id = id;
18+
}
819

9-
public int getId() {
10-
return id;
11-
}
20+
public String getName() {
21+
return name;
22+
}
1223

13-
public void setId(int id) {
14-
this.id = id;
15-
}
24+
public void setName(String name) {
25+
this.name = name;
26+
}
1627

17-
public String getName() {
18-
return name;
19-
}
28+
public Division getDivision() {
29+
return division;
30+
}
2031

21-
public void setName(String name) {
22-
this.name = name;
23-
}
32+
public void setDivision(Division division) {
33+
this.division = division;
34+
}
2435

25-
public Division getDivision() {
26-
return division;
27-
}
36+
public Date getStartDt() {
37+
return startDt;
38+
}
2839

29-
public void setDivision(Division division) {
30-
this.division = division;
31-
}
40+
public void setStartDt(Date startDt) {
41+
this.startDt = startDt;
42+
}
3243

3344
}

‎mapstruct/src/main/java/org/baeldung/entity/SimpleDestination.java‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
public class SimpleDestination {
44

5-
private String name;
6-
private String description;
7-
8-
public String getName() {
9-
return name;
10-
}
5+
private String name;
6+
private String description;
117

12-
public void setName(String name) {
13-
this.name = name;
14-
}
8+
public String getName() {
9+
return name;
10+
}
1511

16-
public String getDescription() {
17-
return description;
18-
}
12+
public void setName(String name) {
13+
this.name = name;
14+
}
1915

20-
public void setDescription(String description) {
21-
this.description = description;
22-
}
16+
public String getDescription() {
17+
return description;
18+
}
19+
20+
public void setDescription(String description) {
21+
this.description = description;
22+
}
2323

2424
}

0 commit comments

Comments
 (0)