title: How to delete particular data from database table by using spring boot?
body: <p>I have created a login page on which I have mentioned the forgot password link which redirect user to the page where they have to insert email address in order to receive the token generated from the program. With the help of this token user is redirected to change password page where he/she is able to change their password.</p>
  
  <p>Now, my concern is to set the expiry time to that token which is stored in database and should get deleted after that particular time.
  How can I do this by using Spring boot?</p>
  
  <p><em>This controller generates and save the token in database.</em></p>
  
  <pre><code>@RequestMapping(value = "/forgotPassword", method = RequestMethod.POST)
  @ResponseBody
  public String forgotPassword(HttpServletRequest request, String email) {
  
      Client user = clientService.getClientByEmail(email);
      if (user != null) {
  
          user.setConfirmationToken(UUID.randomUUID().toString());
          clientService.updateUser(user);
  
          String appUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
  
          SimpleMailMessage registrationEmail = new SimpleMailMessage();
          registrationEmail.setTo(user.getEmail());
          registrationEmail.setSubject("Link Confirmation");
          registrationEmail.setText("Hi " + user.getFirstname()
                  + ", To confirm your e-mail address and continue change password              , please  click to the belo link:\n"
                  + appUrl + "/confirm/" + user.getConfirmationToken());
          // registrationEmail.setFrom("noreply@domain.com");
  
          emailService.sendEmail(registrationEmail);
  
          return "A confirmation e-mail has been sent to " + user.getEmail();
  
      } else
          return "email does not exitst with any user";
  }
  </code></pre>
  
  <p><em>This controller redirects the changePassword page when a token is clicked</em></p>
  
  <pre><code>@RequestMapping(value = "/confirm/{token}", method = RequestMethod.GET)
  public ModelAndView confirmEmail(@PathVariable("token") String confirmationToken, Model m,Client c,Principal p) {
      ModelAndView mv=new ModelAndView();
      Client user = clientService.getClientByconfirmationToken(confirmationToken);
  
      if (p != null) {
          return new ModelAndView("redirect:/dashboard");
      }
  
      if (user != null ) {
          m.addAttribute("token",user.getConfirmationToken());
          mv.setViewName("/changePassword");
          return mv;
  
      } 
  
      else {
          mv.setViewName("redirect:/changePassword?invalidToken");
      }
          return mv;
  
  }
  </code></pre>