select下拉框回显的解决办法

在项目中:想实现点击“查询排班表”,进来右边的页面,年月自动回显成当前年月;同时,实现往前,往后,跳转都能回显,年月是下拉框的形式;
select下拉框回显的解决办法
文章图片


部分代码:
【select下拉框回显的解决办法】@RequestMapping(value = "https://www.it610.com/article/{type}/{deptId}/{yearMonth}/{datemap}")
public String getData(@PathVariable String type, @PathVariable Long deptId, @PathVariable String yearMonth,
@PathVariable String datemap, Model model, HttpServletRequest request) throws Exception {
String nowyear = com.yuanls._comm.util.Utils.getFormatDate("yyyy");
List listYears = new ArrayList(); //年
List listMonths = new ArrayList(); //月
for (int i = 2016; i < Integer.parseInt(nowyear)+2; i++) {
listYears.add(i);
}
for(int i=1; i<10; i++) {
listMonths.add("0"+i);
}
listMonths.add(10);
listMonths.add(11);
listMonths.add(12);
model.addAttribute("listYears", listYears);
model.addAttribute("listMonths", listMonths);
String selectYear = yearMonth.substring(0, yearMonth.length()-2); //当前年
String selectMonth = yearMonth.substring(4, yearMonth.length()); //当前月
model.addAttribute("year1", selectYear);
model.addAttribute("month1", selectMonth);

}
jsp部分代码:通过遍历显示下拉年月;这样比较灵活;通过js来判断回显;


















补充select回显方法:

  1. 1.
  2. 2.
  3. 3.


    推荐阅读