业务场景:
导出按钮是否显示的条件如下:
1、必须选择开始时间和结束时间
2、根据筛选条件查询必须存在数据
3、当点击提交后并且满足如上两个条件,导出按钮变为可选后,如果用户修改了筛选条件则必须把 导出 按钮设为不可选
实现的方式有两种:
1、form表单提交 controller层响应一个页面
页面:
用户类型: 请选择 普通用户 尊享用户 VIP VVIP 开始时间: 结束时间: 导出 提交controller层:
@RequestMapping("findUserAll2") public String findUserAll2(HttpServletRequest request,@Param("type") String type,@Param("beginDate") String beginDate,@Param("endDate") String endDate){ log.info("type:"+type+";beginDate:"+beginDate+";endDate:"+endDate); List userAll = userService.findUserAll(type, beginDate, endDate); //当开始时间和结束时间不为空且 根据查询条件获取的数据size大于0 时 把页面的download属性的值设为1 存入request作用域中 if (beginDate != null && beginDate.trim().length()>0 && endDate != null && endDate.trim().length()>0 && userAll.size()>0) { request.setAttribute("download","1"); } request.setAttribute("type",type); request.setAttribute("beginDate",beginDate); request.setAttribute("endDate",endDate); request.setAttribute("userAll",userAll); return "twoPage"; }
2、ajax请求 controller层仅响应数据
页面:
//因为ajax请求后 设置了新值 并且调用了onchange事件 所以必须在隐含域中设置onchange属性滴调用自定义函数 showBtn()
用户类型: 请选择 普通用户 尊享用户 VIP VVIP 开始时间: 结束时间: 导出 提交controller层:
@RequestMapping("findUserAll")@ResponseBodypublic List findUserAll(HttpServletRequest request,@Param("type") String type,@Param("beginDate") String beginDate,@Param("endDate") String endDate){ log.info("type:"+type+";beginDate:"+beginDate+";endDate:"+endDate); List userAll = userService.findUserAll(type, beginDate, endDate); return userAll;}
如果这个两个方式 均实测正常代码已上传到git 地址:https://github.com/ganguixu/springboot_jsp.git
Original: https://www.cnblogs.com/ganguixu/p/15026556.html
Author: 干桂旭
Title: jsp change事件
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/591890/
转载文章受原作者版权保护。转载请注明原作者出处!