title: How to Update a record in spring boot and mysql
body: <p>I am a newbie to spring boot.I have created a crud operation and the insert operation is working properly. I have a challenge on the update operation , the program is giving an error on the web page</p>
  <p><strong>Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.Wed Jul 22 20:39:03 CAT 2020 There was an unexpected error (type=Bad Request, status=400)</strong></p>
  <p>and the following error from the console</p>
  <p><strong>Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: &quot;saveEmployee&quot;]</strong></p>
  <p>how can I solve the problem?</p>
  <p>my code is below</p>
  <p>Controller Class</p>
  <pre><code>```
  package com.zimprogrammer.springboot.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  
  import com.zimprogrammer.springboot.model.Employee;
  import com.zimprogrammer.springboot.service.EmployeeService;
  
  @Controller 
  public class EmployeeController {
  
      @Autowired
      private EmployeeService employeeService;
      
      @GetMapping(&quot;/&quot;)
      public String vieHomePage(Model model) {
      
          // this shows a list of employees
          model.addAttribute(&quot;listEmployees&quot;, employeeService.getAllEmployees());
          return &quot;index&quot;;
      }
      
      @GetMapping(&quot;/showEmployeeForm&quot;)
      public String showEmployeeForm(Model model){
          
          //request for the form to enter the data 
          Employee employee =new Employee();
          model.addAttribute(&quot;employee&quot;, employee);
          return &quot;new_employee&quot;;
      
      }
      
      @PostMapping(&quot;/saveEmployee&quot;)
      public String saveEmployee(@ModelAttribute(&quot;employee&quot;) Employee employee) {
          //save data to the database
          
          employeeService.saveEmployee(employee);
          return &quot;redirect:/&quot;;
      }
      
      @GetMapping(&quot;/showFormForUpdate/{id}&quot;)
      public String showFormForUpdate(@PathVariable( value=&quot;id&quot;) long id, Model model) {
          //get the employee from the service
          
          Employee employee =employeeService.getEmployeeById(id);
          
          // set the employee to pre-populate the form
          model.addAttribute(&quot;employee&quot;, employee);
          
          return &quot;update_employee&quot;;
          
      }
  }```
  
  Employee Service Interface
  ```package com.zimprogrammer.springboot.service;
  
  import java.util.List;
  
  import com.zimprogrammer.springboot.model.Employee;
  
  public interface EmployeeService {
      List&lt;Employee&gt; getAllEmployees();
  
      void saveEmployee(Employee employee);
      Employee getEmployeeById(long id);
  }
  ```
  Employee Service Class 
  ```
  package com.zimprogrammer.springboot.service;
  
  import java.util.List;
  import java.util.Optional;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  
  import com.zimprogrammer.springboot.model.Employee;
  import com.zimprogrammer.springboot.repository.EmployeeRepository;
  
  @Service
  public class EmployeeServiceImpl implements EmployeeService{
  
      @Autowired
      private EmployeeRepository employeeRepository;
      
      @Override
      public List&lt;Employee&gt; getAllEmployees() {
          return employeeRepository.findAll();
      
      }
      
      @Override
      public void saveEmployee(Employee employee) {
          this.employeeRepository.save(employee);
      }
  
      @Override
      public Employee getEmployeeById(long id) {
          Optional&lt;Employee&gt; optional=employeeRepository.findById(id);
          Employee employee=null;
          
          if(optional.isPresent()) {
              employee=optional.get();
          }else {
              throw new RuntimeException(&quot;User not found for id::&quot; + id);
          }
          return employee;
      }
  }
  ```
  </code></pre>
  <p>Employee Repository Interface
  ```
  package com.zimprogrammer.springboot.repository;</p>
  <pre><code>import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  import com.zimprogrammer.springboot.model.Employee;
  
  @Repository
  public interface EmployeeRepository extends JpaRepository&lt;Employee, Long&gt;{
  
  }
  ```
  Update Form : Thymeleaf and bootstrap
  ```
  &lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot; xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;ISO-8859-1&quot;&gt;
  &lt;title&gt;Employee Management System&lt;/title&gt;
  
  &lt;!-- Latest compiled and minified CSS --&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot; integrity=&quot;sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u&quot; crossorigin=&quot;anonymous&quot;&gt;
  
  &lt;!-- Optional theme --&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css&quot; integrity=&quot;sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp&quot; crossorigin=&quot;anonymous&quot;&gt;
  
  &lt;!-- Latest compiled and minified JavaScript --&gt;
  &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&quot; integrity=&quot;sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class=&quot;container&quot; style=&quot;width:40%; height:40%;&quot;&gt;
          &lt;h1&gt;Employee Management system&lt;/h1&gt;
          &lt;hr&gt;
          &lt;h2&gt;Update Employee&lt;/h2&gt;
  
          &lt;form action=&quot;#&quot; th:action=&quot;@{saveEmployee}&quot; th:object=&quot;${employee}&quot;
              method=&quot;POST&quot;&gt;
              
              &lt;input type=&quot;hidden&quot; th:field=&quot;*{id}&quot; /&gt;
              
              &lt;input type=&quot;text&quot; th:field=&quot;*{firstName}&quot;
              class=&quot;form-control mb-4 col-4&quot;&gt;
              &lt;input type=&quot;text&quot; th:field=&quot;*{lastName}&quot;
                   class=&quot;form-control mb-4 col-4&quot;&gt;
              &lt;input type=&quot;text&quot; th:field=&quot;*{email}&quot;
                  class=&quot;form-control mb-4 col-4&quot;&gt;
              &lt;button type=&quot;submit&quot; class=&quot;btn btn-info col-2&quot;&gt;Update
                  Employee&lt;/button&gt;
  
          &lt;/form&gt;
          &lt;hr&gt;
          
          &lt;a th:href = &quot;@{/}&quot;&gt; Back to Employee List&lt;/a&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ```
  </code></pre>