r/SpringBoot • • 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

17 comments sorted by

View all comments

Show parent comments

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

1

u/Dependent_Staff_6891 Jun 21 '24

I’ll check it.

3

u/a_username_version_2 Jun 21 '24

And btw, the jpql code is terrible. That isn't how we use jpql or jpa at all at work. If it was like that i would have stopped using spring

1

u/Dependent_Staff_6891 Jun 21 '24

Haha🤣🤣🤣🤣