I'm using spring boot and I wanted to fill a select option menu from my database table for which I've done the following
In my controller class I've
@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;
}
here I've returned two objects of "list" and "teamKey" for list i've populated table and for teamKey I want to populate a dropdown for user selection. here is my 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>
I've copied this example from here but It only shows empty dropdown and I do have value inside my database table and I've checked it by filling table grid with "teamKey".
here is my hub class
@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;
}