title: Spring Boot object between controller in different class
body: <p>I am trying to get a object sent to a Spring-boot controller in one Class to be available in the model of another controller.</p>
  
  <p>It seems like <code>@SessionAttributes</code> is for objects that are global (like the logged on user). </p>
  
  <p>I have tried this on <strong>controller 1</strong></p>
  
  <pre><code>@Component
  @Controller
  @SessionAttributes(value = { "user"})
  public class FormController {
  
      @GetMapping("/occurence/{occno}")
  public String findOcc(@PathVariable String occno, OccViewModel occViewModel, Model model) {
  
      Occ occ = occRepository.findByOccno(occno);
      occViewModel.setOcc(occ);
      occViewModel.setPersons(occPersonRepository.findOccPersonByOcc(occ.getId()));
      List&lt;OccPerson.OccRole&gt; occRoles = Arrays.asList(OccPerson.OccRole.values());
      model.addAttribute("occRoles", occRoles);
      model.addAttribute("occViewModel", occViewModel);
      model.addAttribute("countries", countries);
      return "occ";
  }
  </code></pre>
  
  <p>I have a button on this form which sends the user to this endpoint - I would like the same occViewModel to available to this endpoint on <strong>controller 2</strong></p>
  
  <pre><code>@Component
  @Controller
  @SessionAttributes(value = { "user" })
  public class PlanController {
  
  @GetMapping("/newplan")
  public String newPlan(Model model, OccViewModel occViewModel, HttpSession session) {
      // create PlanViewModel DTO
      Occ occ = new occVieModel.getOcc();
      PlanViewModel planViewModel = new PlanViewModel;
      planViewModel.setOcc(occ);
      model.addAttribute(planViewModel);
      //etc
  }
  </code></pre>
  
  <p>I see there is @SessionAttributes but  i do not understand in my first controller how I would even load it into the session if I dont know what Occ to get from the repo as it appears you need to @ModelAttribute prior to the handler - but the URI gives the occno?</p>
  
  <p>I looked <a href="https://stackoverflow.com/questions/21426519/spring-mvc-pass-same-object-between-controller">here</a> also but it appeared do deal with the same class only and it wasn't clear how you would apply this to a id passed in on the URI.</p>