我的下拉列表中有类似的问题没有显示任何值。喜欢 解决方案:使用Thymeleaf和SpringBoot的下拉列表没有数据显示 在下拉列表中。如果我查看IE调试器,我可以看到我的列表 下拉列表,但下拉列表不会显示我的列表以供选择。 HTML代码段位于:
<div class="col-lg-3 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i
class="glyphicon glyphicon-list"></i></span>
<select th:field="*{savings_type}" name="savings_type_id"
id="savings_type_id" class="form-control selectpicker">
<option value="">Select Savings Type</option>
<option th:each="dropDownItem : ${leanTypesList}"
th:value="${dropDownItem.lt_id}"
th:text="${dropDownItem.lt_name}">
</option>
</select>
</div>
</div>
此处的代码: 我的模型leanDeatil.java - 填充Savings_Type字段的数据 这也是值得的。
@Entity
@Table(name="lean_detail")
public class LeanDetail implements Serializable {
private static final long serialVersionUID = 1L;
@Id
//@Column (name="LEANDETAIL_ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column (name="SAVINGS_TYPE")
private int savings_type;
@Column (name="SAVING_AMOUNT")
private BigDecimal saving_amount;
@Column (name="TITLE")
private String title;
@Column (nullable=true, name="IMPROVEMENT_DESC")
private String improvement_desc;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "SAVINGS_TYPE", referencedColumnName = "lt_id",
insertable = false, updatable = false)
private LeanTypes leanTypes;
public LeanDetail(){}
public LeanDetail(String title,int savings_type, BigDecimal saving_amount,
String improvement_desc {
super();
this.title = title;
this.savings_type = savings_type;
this.saving_amount = saving_amount;
this.improvement_desc = improvement_desc;
}
getters and setters....
我的模型leanTypes.java数据来自
@Entity
@Table(name="lean_types")
public class LeanTypes {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column (name="LT_ID")
private int lt_id;
@Column (name="LT_NAME")
private String lt_name;
@Column (name="LT_DESC")
private String lt_desc;
@Column(nullable=false, name="LT_ACTV")
private boolean lt_actv;
@OneToMany(mappedBy="leanTypes", fetch=FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
private List<LeanDetail> leanDetail = new ArrayList<LeanDetail>();
public LeanTypes(){}
public LeanTypes(int lt_id, String lt_name, String lt_desc, Boolean lt_actv) {
super();
this.lt_id = lt_id;
this.lt_name = lt_name;
this.lt_desc = lt_desc;
this.lt_actv = lt_actv;
}
getters and setters....
}
来自我的Controller LeanDetail.java
@GetMapping("/update-leanDetail")
public String updateLeanDetail(@RequestParam int id, HttpServletRequest
request){
request.setAttribute("leanTypesList", leanTypesService.findAll());
request.setAttribute("leanDetail", leanDetailService.findLeanDetail
(id));
request.setAttribute("mode", "MODE_UPDATE");
return "leanDetail";
}