title: Spring. ModelAttribute. GetMapping. THYMELEAF
body: <p>Program can't resolve objects that i give it in html from controller. </p>
  
  <p>The Model</p>
  
  <pre><code>public class Taco {
  
      private String name;
      private List&lt;String&gt; ingredients;
  }
  </code></pre>
  
  <p>The Ingredient </p>
  
  <pre><code>public class Ingredient {
  
      private final String id;
      private final String name;
      private final Type type;
  
  
  
      public static enum Type {
          WRAP, PROTEIN, VEGGIES, CHEESE, SAUCE
      }
  
  }
  </code></pre>
  
  <p>In Controller. I tried different variations of ModelAttribute in different methods, followed a lot of examples. But HTML still can't resolve.</p>
  
  <pre><code>@Slf4j
  @Controller
  @RequestMapping("/design")
  public class DesignTacoController {
  
  
  
  public void addIngredientsToModel(Model model) {
      List&lt;Ingredient&gt; ingredients = Arrays.asList(
              new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
              new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
              new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
              new Ingredient("CARN", "Carnitas", Type.PROTEIN),
              new Ingredient("TMTO", "Diced Tomatoes", Type.VEGGIES),
              new Ingredient("LETC", "Lettuce", Type.VEGGIES),
              new Ingredient("CHED", "Cheddar", Type.CHEESE),
              new Ingredient("JACK", "Monterrey Jack", Type.CHEESE),
              new Ingredient("SLSA", "Salsa", Type.SAUCE),
              new Ingredient("SRCR", "Sour Cream", Type.SAUCE)
      );
  
      Type[] types = Ingredient.Type.values();
      for (Type type : types) {
          model.addAttribute(type.toString().toLowerCase(),
                  filterByType(ingredients, type));
      }
  }
  
  
  @GetMapping
  @ModelAttribute("design")
  public String showDesignForm(Model model) {
      addIngredientsToModel(model);
      model.addAttribute("design", new Taco());
      return "design";
  }
  
  
  private List&lt;Ingredient&gt; filterByType(
          List&lt;Ingredient&gt; ingredients, Type type) {
      return ingredients
              .stream()
              .filter(x -&gt; x.getType().equals(type))
              .collect(Collectors.toList());
  }}
  </code></pre>
  
  <p>Now part of design.html. Cant resolve protein, ingredient.id, ingredient.name. How can I fix this? I tried different ways:</p>
  
  <pre><code>&lt;form method="POST" th:object="${design}"&gt;
     &lt;div&gt;
          &lt;h3&gt;Pick your protein:&lt;/h3&gt;
          &lt;div th:each="ingredient : ${protein}"&gt;
              &lt;input name="ingredients"
              type="checkbox"th:value="${ingredient.id}" /&gt;
              &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>