Member-only story
Spring Boot MapStruct
In this tutorial, we will learn What is MapStruct and why we need to use MapStruct in our spring boot application and How to setup MapStruct in spring boot application while using Lombok library.
What is MapStruct ?
MapStruct is a code generator that automates the process of mapping between java beans and also simplify the implementation of mappings between java bean types.
The generated mapping code uses plain method invocation and this is fast, type-safe and easy to understand and also eliminate the need for manual mapping code.
Why use MapStruct ?
With MapStruct, we only need to create the interface and the library will automatically generate a concrete implementation during compile time which ensures a high performance and also improves the code readability, maintainability and developer productivity. For Example : A common type of conversion happen between entities and DTOs that go out to the client side. So that is the problem MapStruct solves : Manual creating bean mapper is time consuming. But the library can generate bean mapper classes automatically.
DTO Design Pattern and Why we use DTO :
DTO is a design pattern. It creates an additional barrier and modifies the request/responses.
As you saw, we fetched data absolutely like the same from DB as it is, and we have not had a chance to hide some data or modify the data. DTO allow us to make this.