<option value=" " selected="selected">请选择</option>
<c:forEach items="${sessionScope.gysgcxm}" var="item2">
<option value="${item2.pstcd}"> ${item2.pstcd}</option>
</c:forEach>
</select>
如上: <option value=" " selected="selected">请选择</option>,注意value=""双引号里的空值或许要空格或不要空格,看情况决定。
动态下拉框默认值:
List stcdlist = queryrainService.querystationstcd(null);
HashMap queryParams = new HashMap();
queryParams.put("stationstcd", stcdlist);//动态下拉框的值
if(stcd != null && !"".equals(stcd.trim())) {
queryParams.put("stcd", stcd);//默认值,也即回显值
} else {
queryParams.put("stcd", ((Map)stcdlist.get(0)).get("stcd"));//动态下拉框默认值
}
<td style="width:150px;height:10%;">
<label>测站编码</label>
<select id="stcd" name="stcd" value="${stcd}">//接收回显值
<option value="" selected="selected">请选择</option>
<c:forEach items="${stationstcd}" var="item2">
<option value="${item2.stcd}">${item2.stnm}(${item2.stcd})</option>
</c:forEach>
</select>
</td>
默认时间:
//默认取最近一周的时间
Calendar cal = Calendar.getInstance();
java.util.Date tmbegin2 = cal.getTime();
java.sql.Timestamp tmbegin = null;
if (!isNull(tmbegin1)) {
try {
tmbegin2 = (java.util.Date) sdf.parse(tmbegin1);
tmbegin = new java.sql.Timestamp(tmbegin2.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
java.util.Date tmend2 = cal.getTime();
java.sql.Timestamp tmend = null;
if (!isNull(tmend1)) {
try {
tmend2 = (java.util.Date) sdf.parse(tmend1);
tmend = new java.sql.Timestamp(tmend2.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
PageInfo pageInfo = new PageInfo();
if(stcd != null && !"".equals(stcd.trim())) {
queryParams.put("stcd", stcd);
} else {
queryParams.put("stcd", ((Map)stcdlist.get(0)).get("stcd"));
}
String nowtime2 = sdf.format(cal.getTime());
cal.add(Calendar.WEEK_OF_YEAR, -1);
String nowtime1 = sdf.format(cal.getTime());
if (!isNull(tmbegin1)) {
queryParams.put("tmbegin", tmbegin1);
} else {
queryParams.put("tmbegin", nowtime1);
}
if (!isNull(tmend1)) {
queryParams.put("tmend", tmend1);
} else {
queryParams.put("tmend", nowtime2);
}
还可以:
Date now = new Date();
SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowtime1 = dateFormat1.format( now )+"-01 00:00:00";
String nowtime2 = dateFormat2.format( now );