-5
這是我的控制器投設置成列表:如何在這種情況下
private void setUniqueSignSize(List<TemplateMasterModel> templateTypeList, final Map<String, Object> model) {
Set<String> signSizeList = new HashSet<String>();
for(TemplateMasterModel templateType: templateTypeList) {
signSizeList.add(templateType.getTemplateGrpCode());
}
model.put("signSizeList", signSizeList);
//getPaperTypes(templateTypeList, signSizeList, model);
}
這是我的jsp:
<table style="width:500px; margin-bottom: 10px;margin-left:50px;">
<tr>
<td class="requiredFieldIndicator">Sine Size</td>
<td>
<input type="hidden" name="tempTypeName" id="tempTypeName" value="">
<select name="signTypeDesc" id="signTypeDesc" onchange="setTemplChangeValue();" style="width: 200px">
<%
String changeY = "";
if(request.getAttribute("changeY") != null){
changeY = String.valueOf(request.getAttribute("changeY"));
}
List<TemplateMasterModel> templateTypeList = (List) request.getAttribute("signSizeList");
if(templateTypeList != null && templateTypeList.size() != 0){
if(templateTypeList.size() == 1)
{
if(changeY.equals("No"))
{
%><option value="Select">None Selected</option><%
}
%>
<option value="<%=templateTypeList.get(0).getTemplateGrpCode()%>"><%=templateTypeList.get(0).getTemplateGrpCode()%></option>
<%
}
我如何轉換一組,signSizeList
,到一個列表?
['new ArrayList(signSizeList)'](http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html#ArrayList(java.util.Collection)) – iamnotmaynard
Why你是否想要更改爲列表,爲什麼不直接使用該設置?如果唯一的原因是你想要唯一的元素,使用'if(set.size()== 1){Model model = set.iterator()。next(); }' – Andreas