title: java spring boot passing data to frontend
body: <p>we have homework that i am struggling with. What i want to do first is to pass data to frontend.
  This is my project structure.<br>
  <a href="https://i.stack.imgur.com/W7r1e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W7r1e.png" alt="enter image description here"></a></p>
  
  <p>I want to print all users to frontend.</p>
  
  <p>UserService  </p>
  
  <pre><code>@Service
      public class UserService {
          private final Map&lt;Long, User&gt; users;
  
          public UserService(Map&lt;Long, User&gt; users) {
              this.users = users;
          }
  
          public Map&lt;Long, User&gt; findAllUsers() {
              return users;
          }
      }
  </code></pre>
  
  <p>UserController</p>
  
  <pre><code>@Controller
  @RequestMapping("/user")
  
  public class UserController {
  
      private final UserService userService;
  
      @Autowired
      public UserController(UserService userService) {
          this.userService = userService;
      }
  
      @GetMapping("/")
      public String all(Model model) {
          model.addAttribute("users", userService.findAllUsers() );
          return "user/all";
      }
  }
  </code></pre>
  
  <p>And main that runs the application and where I am creating two users</p>
  
  <pre><code>@Slf4j
  @Controller
  @SpringBootApplication
  public class MvcListApplication implements CommandLineRunner {
  
  
  
      public static void main(String[] args) {
  
          Engine company = new Engine();
          User user;
          User employee;
          user = company.createUser("fsdfsd","fsdfsd",49484894,"gfdgfdg@fdgfd.com",918191,"fsdfsd","Ulica",456);
          employee = company.createUser("fsdfsd","fsdfsd",494894,"gfdgfdg@fdgfd.com",918191,"fyrtytr","Ulica",456);
  
          SpringApplication.run(MvcListApplication.class, args);
          log.info("Open in browser: http://localhost:8080");
      }
  
      @Override
      public void run(String... args) throws Exception {
  
      }
  
  
  }
  </code></pre>
  
  <p>User class</p>
  
  <pre><code>    public class User {
  
          private String ID;
          private String firstName;
          private String lastName;
          private int idNumber;
          private String email;
          private Address officialAddress;
          private Address postAddress;
          private List&lt;String&gt; contracts = new ArrayList&lt;&gt;();
  
  
          public User(String firstName, String lastName, int idNumber, String email, Address officialAddress, Address postAddress) {
              ID = UUID.randomUUID().toString();
              setFirstName(firstName);
              setLastName(lastName);
              setIdNumber(idNumber);
              setEmail(email);
              setOfficialAddress(officialAddress);
              setPostAddress(postAddress);
          }
  
  getters/setters
  </code></pre>
  
  <p>And my frontend templates/user/all</p>
  
  <pre><code>&lt;tr th:each="user: ${users}"&gt;
      &lt;td th:text="${user.id}"&gt;&lt;/td&gt;
      &lt;td th:text="${user.firstName}"&gt;&lt;/td&gt;
      &lt;td th:text="${user.lastName}"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>I am just trying to glue some things together to make it work but it just won't work. 
  It runs but i cant see any results no users only hardcoded html on url /users. Thanks for any help</p>