title: Spring Data JPA findOne() change to Optional how to use this?
body: <p>I'm learning <code>SpringBoot2.0</code> with <code>Java8</code>.</p>
  
  <p>And I followed some blog-making tutorial example.</p>
  
  <p>The tutorial source code is:</p>
  
  <pre><code>@GetMapping("/{id}/edit")
  public String edit(@PathVariable Long id, Model model) {
    model.addAttribute("categoryDto", categoryService.findOne(id));
    return "category/edit";
  }
  </code></pre>
  
  <p>But this code is throwing this error:</p>
  
  <blockquote>
    <p>categoryService.findOne(id)</p>
  </blockquote>
  
  <p>I'm thinking about changing the JPA <code>findOne()</code> method to <code>Optional&lt; S &gt;</code></p>
  
  <p>How to solve that?</p>
  
  <p>More info:</p>
  
  <p>This is the categoryService method:</p>
  
  <pre><code>public Category findOne(Long id) {
    return categoryRepository.findOne(id);
  }
  </code></pre>