File tree Expand file tree Collapse file tree
mapstruct/src/main/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .dto ;
2+
3+ public class TransactionDTO {
4+
5+ private String uuid ;
6+ private Long totalInCents ;
7+
8+ public String getUuid () {
9+ return uuid ;
10+ }
11+
12+ public void setUuid (String uuid ) {
13+ this .uuid = uuid ;
14+ }
15+
16+ public Long getTotalInCents () {
17+ return totalInCents ;
18+ }
19+
20+ public void setTotalInCents (Long totalInCents ) {
21+ this .totalInCents = totalInCents ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .entity ;
2+
3+ import java .math .BigDecimal ;
4+ import java .util .UUID ;
5+
6+ public class Transaction {
7+
8+ private Long id ;
9+ private String uuid = UUID .randomUUID ().toString ();
10+ private BigDecimal total ;
11+
12+ public Long getId () {
13+ return id ;
14+ }
15+
16+ public String getUuid () {
17+ return uuid ;
18+ }
19+
20+ public BigDecimal getTotal () {
21+ return total ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .mapper ;
2+
3+ import java .math .BigDecimal ;
4+ import java .util .Collection ;
5+ import java .util .List ;
6+
7+ import org .mapstruct .Mapper ;
8+
9+ import com .baeldung .dto .TransactionDTO ;
10+ import com .baeldung .entity .Transaction ;
11+
12+ @ Mapper
13+ abstract class TransactionMapper {
14+
15+ public TransactionDTO toTransactionDTO (Transaction transaction ) {
16+ TransactionDTO transactionDTO = new TransactionDTO ();
17+ transactionDTO .setUuid (transaction .getUuid ());
18+ transactionDTO .setTotalInCents (transaction .getTotal ().multiply (new BigDecimal ("100" )).longValue ());
19+ return transactionDTO ;
20+ }
21+
22+ public abstract List <TransactionDTO > toTransactionDTO (Collection <Transaction > transactions );
23+ }
You can’t perform that action at this time.
0 commit comments