2017-11-25 2 views
0

Wie man th anwendet: jeder auf th: Schalter für Werte von Enum im folgenden Fall?Thymeleaf th: Schalter mit th: each

public enum Framework { 
    ABC0(0, "Name0"), 
    ABC1(1, "Name1"), 
    ABC2(2, "Name2"), 
    ABC3(3, "Name3"); 

    public int id; 
    public String name; 

    private Framework (int id, String name){ 
      this.id = id;  
      this.name = name; 
    } 
} 

und in Modellklasse habe ich ein Feld:

private int frameworkId; 

Danke

Antwort

0

ich es herausgefunden - es ist ganz einfach.

ich übergebenen Werte von Rahmen in Controller-Klasse zu bilden:

model.addAttribute("frameworks", Framework.values()); 

und dann:

   <span class="cls">Framework:</span> 
       <span th:switch="${item.frameworkId}"> 
        <span th:each="fw : ${frameworks}"> 
         <span th:case="${fw.id}" th:text="${fw.name}"></span> 
        </span>    
       </span> 
Verwandte Themen