title: Using hashmap as a database in Java Spring MVC
body: <p>Im trying to create a login in Java, SpringBoot, and HTML (thymeleaf) but using a hashmap to store the username and password instead of SQL or the built in support. Im having trouble with it because it prints the hashmap on the website (im also trying to show those 2 values on the website), but it does it empty like this: " {} "
  Here's what I've done:</p>
  
  <p>Setters and getters:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Map;
  
  public class Greeting {
     // id = username. content = password.
      private String id;
      private String content;
  public Map&lt;String, String&gt; userAndPassword = new HashMap&lt;&gt;();
  
  public void setId(String id) {
      // username
      this.id = id;
  }
  
  public String getId() {
      return id;
  }
  
  public void setContent(String content) {
      this.content = content;
  }
  
  public String getContent() {
      return content;
  }
  
  public void setuserAndPassword(Map&lt;String,String&gt; userAndPassword) {
      this.userAndPassword = userAndPassword;
      // adding username and password into the hashmap
      userAndPassword.put(id, content);
  }
  
  public Map&lt;String, String&gt; getuserAndPassword() {
      return userAndPassword;
  }
  }
  </code></pre>
  
  <p>The view (result.html):</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;title&gt;Web Login&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Datos&lt;/h1&gt;
      &lt;p th:text="'User ID: ' + ${greeting.id}" /&gt;
      &lt;p th:text="'Password: ' + ${greeting.content}" /&gt;
      &lt;p th:text="'Printing out hashmap with all data: ' + ${greeting.userAndPassword}" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>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.PostMapping;
  
  @Controller
  public class GreetingController {
  
      @GetMapping("/greeting")
      public String greetingForm(Model model) {
          model.addAttribute("greeting", new Greeting());
          return "greeting";
      }
  
      @PostMapping("/greeting")
      public String greetingSubmit(@ModelAttribute Greeting greeting) {
          return "result";
      }
  
  }
  </code></pre>