对于后台进行请假日期验证,如果有重复可以判断,如法提交
1 public String doAddLeaves(){ 2 try { 3 TbUser tbUser=(TbUser) getFromSession("loginUser"); 4 leaveList=leaveService.getLeavesByUsername(tbUser.getId());//获取当前用户所有请假条 5 int row = 0; 6 //System.err.println("======="+tbLeave.getBeginLeave()+","+tbLeave.getEndLeave()); 7 for (TbLeave leaves : leaveList) { 8 if (tbLeave.getEndLeave().compareTo(leaves.getBeginLeave())<=0 9 || tbLeave.getBeginLeave().compareTo(leaves.getEndLeave())>=0 ) { 10 11 //System.err.println("1..."+tbLeave.getBeginLeave()+","+tbLeave.getEndLeave()); 12 //System.err.println("2..."+leaves.getBeginLeave()+","+leaves.getEndLeave()); 13 row=0; 14 15 }else{ 16 row=1; 17 break; 18 } 19 } 20 if (tbLeave.getEndLeave().compareTo(tbLeave.getBeginLeave())<0) { 21 log.info("fail!!!"); 22 resultMap.put("retcode", RetCode.FAIL); 23 resultMap.put("retmsg", "请假时间需要大于开始时间"); 24 }else { 25 26 if (row==0) { 27 28 leaveService.addLeaves(tbLeave); 29 //putToSession("leave", leave) 30 log.info("success!!!"); 31 resultMap.put("retcode", RetCode.SUCCESS); 32 resultMap.put("retmsg", "保存成功"); 33 }else{ 34 log.info("fail!!!"); 35 resultMap.put("retcode", RetCode.FAIL); 36 resultMap.put("retmsg", "请假时间存在冲突"); 37 } 38 } 39 } catch (Exception e) { 40 e.printStackTrace(); 41 log.error("method addEmails bug:{}",e); 42 resultMap.put("retcode", RetCode.UNKOWN_WRONG); 43 resultMap.put("retmsg", "未知错误,请重试或联系管理员"); 44 } 45 return SUCCESS; 46 }
action
1 <tr> 2 <td align="right" width="30%">开始时间:</td> 3 <td align="left"><input type="text" name="tbLeave.beginLeave" readOnly="readonly" 4 id="beginLeave" 5 onClick="WdatePicker({minDate:‘%y-%M-{%d+1}‘,maxDate:‘#F{$dp.$D(\‘endLeave\‘)}‘,onpicked:function(){endLeave.click();},disabledDays:[0,6]})" class="Wdate" /><br/> 6 </td> 7 </tr><br/> 8 <tr> 9 <td align="right" width="30%">结束时间:</td> 10 <td align="left"><input type="text" name="tbLeave.endLeave" readOnly="readonly" 11 id="endLeave" onClick="WdatePicker({errDealMode:3,minDate:‘#F{$dp.$D(\‘beginLeave\‘)}‘,disabledDays:[0,6]})" class="Wdate"/><br/></td> 12 </tr>
jsp
1 <script type="text/javascript"> 2 $(function() { 3 4 $("#loginForm").validate({ 5 rules : { 6 "tbLeave.beginLeave" : { 7 required : true, 8 }, 9 "tbLeave.endLeave" : { 10 required : true, 11 /* remote: { 12 url: "${ctx}/leave/beginTOEnd.action", 13 type: "post", 14 dataType: "json", 15 data: { 16 "tbLeave.beginLeave": function(){ 17 return $("#beginLeave").val() 18 }, 19 "tbLeave.endLeave": function(){ 20 return $("#endLeave").val(); 21 } 22 } 23 } */ 24 }, 25 /* "tbLeave.reason" : { 26 required : true, 27 } */ 28 }, 29 messages : { 30 "tbLeave.beginLeave" : { 31 required : "输入开始请假日期", 32 }, 33 "tbLeave.endLeave" : { 34 required : "输入结束请假日期", 35 //remote:"*请假日期不能重复" 36 }, 37 /* "tbLeave.reason" : { 38 required : "输入请假原因", 39 } */ 40 41 } 42 }); 43 44 45 46 $("#sendLeave").click(function() { 47 if ($("#loginForm").valid()) { 48 if(confirm("是否要提交吗?")){ 49 var url = "${ctx}/leave/doAddLeaves.action"; 50 $.post( 51 url, 52 { 53 "tbLeave.isdelete" : $("#isdelete").val(), 54 "tbLeave.read" : $("#read").val(), 55 "tbLeave.tbUserByUserId.id" : $("#isid").val(), 56 "tbLeave.beginLeave" : $("#beginLeave").val(), 57 "tbLeave.endLeave" : $("#endLeave").val(), 58 "tbLeave.reason" : $("#reason").val() 59 }, 60 function(data) { 61 if (data.retcode == "0") { 62 alert("提交成功"); 63 window.location.href = "${ctx}/leave/findAllLeaves.action"; 64 } else { 65 alert(data.retmsg); 66 } 67 }); 68 } 69 } 70 }); 71 }); 72 </script>
script
原文地址:https://www.cnblogs.com/TripMaster/p/11398399.html
时间: 2024-10-12 17:56:27