title: How can convert DTO to Entity in Spring boot?
body: <p>I looked for countless questions.
  But most of the questions were as follows.</p>
  <ol>
  <li>Entity -&gt; Dto</li>
  <li>Entity and Dto have the same attribute value.</li>
  </ol>
  <p>but I don't want this.</p>
  <p>I wonder how I can convert Dto to Entity when if property value present in Entity did not exist in Dto.</p>
  <h1>Some Code</h1>
  <p>dosen't specify the codes for the [annotations, Lombok, jpa, ...etc]
  but it exists!</p>
  <h2>User Entity</h2>
  <pre class="lang-java prettyprint-override"><code>class User {
    Long id,
    String username,
    String email,
    String password
  }
  </code></pre>
  <h2>UserDto</h2>
  <pre class="lang-java prettyprint-override"><code>class UserDto {
    String email
  }
  </code></pre>
  <h2>Post Entity</h2>
  <pre class="lang-java prettyprint-override"><code>class Post {
    Long id,
    String title,
    User user
  
  }
  </code></pre>
  <h2>PostDto</h2>
  <pre class="lang-java prettyprint-override"><code>class PostDto {
    Long id,
    String title,
    String username
  }
  </code></pre>
  <h2>UserService</h2>
  <pre class="lang-java prettyprint-override"><code>...
  
  UserDto findUser(id: Long) {
     ...
  }
  
  ...
  </code></pre>
  <h2>PostService</h2>
  <pre class="lang-java prettyprint-override"><code>...
  
  PostDto savePost(Post post) {
     ...
  }
  
  ...
  </code></pre>
  <h2>PostController</h2>
  <pre class="lang-java prettyprint-override"><code>...
  
  PostDto createPost(@RequestBody PostDto postDto) {
    // spring security
    Long userId = XXX.getUserId()  
  
    ....
  
    UserDto userDto = userService.findUser(userId)
    
    // HERE !! what can i do ??
    // How can i convert userDto to user ?
  
    Post post = new Post(postDto.title, user)
    PostDto newPost = postService.savePost(post)
  }
  
  ...
  
  </code></pre>
  <h1>Question</h1>
  <p>All methods of userService return in DTO.
  how can I set user entity in Post Entity?
  I received a userDto return which has only username.</p>
  <p>What should I do at times like this?</p>
  <ol>
  <li>The repository is not being called directly from the controller.</li>
  <li>The service would like to return the DTO unconditionally.</li>
  <li>Should I create an additional Dto that has the same properties as user entity?</li>
  </ol>