2017-03-17 69 views
0

我使用的是春天的引導,我想從我已經做了以下填寫選擇菜單

在我的控制器類我已經

我的數據庫表填充一個選擇菜單選項
@RequestMapping(value="", method=RequestMethod.GET) 
    public ModelAndView area() { 
     ModelAndView model = new ModelAndView("area"); 
     model.addObject("list", areaService.listAllArea()); 


     model.addObject("teamKey", hubService.listAllHubs());//It works perfectly and do return values 

     return model; 
    } 

在這裏,我又回到「表」和名單我已經填充表「teamKey」的兩個對象和teamKey我想填充供用戶選擇下拉。這裏是我的jsp

<select class="form-control" th:field="${operator.hubID}" id="dropOperator"> 
      <option value="0" th:text="select operator" ></option> 
      <option th:each="operator : ${teamKey}" th:value="${operator.hubID}" th:text="${operator.name}"></option> 
     </select> 

我從here複製這個例子,但它只是顯示空的下拉和我有我的數據庫表中的值,我已經通過填寫表格網格「teamKey」檢查它。

這裏是我的HUB類

@Entity       
@Table(name="Hub") 
public class Hub { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private long hubID; 
    public long getHubID() { 
     return hubID; 
    } 
    public void setHubID(long hubID) { 
     this.hubID = hubID; 
    } 
    public String getName() { 
     return name; 
    } 
    public void setName(String Name) { 
     this.name = Name; 
    } 
    public String getDescription() { 
     return description; 
    } 
    public void setDescription(String description) { 
     this.description = description; 
    } 
    @NotNull 
    private String name; 
    private String description; 

} 
+0

我的模型類確實有hubID項目不得不循環並在其中命名 – Jahangeer

回答

0

我通過集線器像這樣

<select name="hubs" > 
       <c:forEach items="${teamKey}" var="lou"> 
        <option value="${lou.hubID}">${lou.name}</option> 
       </c:forEach> 
      </select> 

希望這有助於其他春天開機