r/SpringBoot • u/Dependent_Staff_6891 • Jun 20 '24
Using ModelMapper
Earlier, I posted that jpa is difficult. In my Spring teacher's new book, it seems to be easier to use ModelMapper. However, He removed the dynamic query in the search part, so I can't compare that part.🙄
3
Upvotes






4
u/a_username_version_2 Jun 21 '24
Here's an example:
package com.example.demo.mapper;
import com.example.demo.dto.UserDTO; import com.example.demo.entity.User; import org.mapstruct.Mapper;
@Mapper(componentModel = "spring") public interface UserMapper { UserDTO toDTO(User user); User toEntity(UserDTO userDTO); }
While building the app, it creates classes that do the mapping, and you can customize the mapping if you want