Ajax進行刪除更新分頁顯示頁面(JSP+Struts2+Poolman)

Ajax進行刪除更新分頁顯示頁面(JSP+Struts2+Poolman)

項目結構:

數據表設計:

申請表:

My97DatePicker插件及其使用文檔免費下載:http://download.csdn.net/detail/u012750578/6597619

顯示列表:

批准:

刪除:

翻頁:

條件查詢:

VIEW(Jsp):

apply.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>My JSP 'Apply.jsp' starting page</title>
    <script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="../plugs/My97DatePicker/WdatePicker.js"></script>
    <script>
        var contextPath=$("#contextPath").val();
        //文檔加載完成時運行
        $(function(){        
            init();            
        })
        function init(){            
            initSchedTime();            
        }
        function onchage(rv){            
            if(rv==1){
                $("#p1").show();
                $("#p2").hide();
                $("#p3").show();
            }else if(rv==2){
                $("#p2").show();
                $("#p3").show();
                $("#p1").hide();
            }else{
                $("#p2").hide();
                $("#p1").hide();
                $("#p3").hide();
            }            
        }
        //獲取單選框的值
        function getapplytype(){
            var value="";
            var radio=document.getElementsByName("dutyApply.apptype");
            for(var i=0;i<radio.length;i++){
                value=radio[i].value;
                break;
            }
            return value;
        }
        //請假申請表單驗證
        function checkApplyForm(){
            var apptype=getapplytype();        
            if(apptype==1){
                if($("#appplace").val().length==0){
                    alert("請您填入出差地點.");
                    return false;//不提交表單
                }
            }else if(apptype==2){
            if($("#appplace").val().length==0){
                alert("請您填入培訓地點");
                return false;
            }
        }
        if($("#appreseon").val().length==0){
            alert("請您填入請假事由.");
            return false;
        }
        var falg=checkDate();
        if(falg==false){
            return false;
        }
        
    }
    //驗證日期:
      function checkDate(){  
          var sc=$("#startcalender").val();
          var ec=$("#endcalender").val();
          var st=$("#appSTime").val();
          var et=$("#appETime").val();
          if(sc.length==0){
              alert("請您選擇請假開始日期!");
              return false;
          }
          if(ec.length==0){
              alert("請您選擇請假結束日期!");
              return false;
          }  
          sc=sc.substring(0,4)+sc.substring(5,7)+sc.substring(8,10);
          ec=ec.substring(0,4)+ec.substring(5,7)+ec.substring(8,10);
          if(getSysdate(sc,st)==false){              
              alert("請假開始時間不能小於當前時間");
              return false;
          }
          if(getSysdate(ec,et)==false){          
              alert("請假結束時間不能小於當前時間");
              return false;
          }          
          if(sc-ec>0){
              alert("請假開始日期不能大於請假結束日期");
              return false;
          }else if(sc==ec){          
              if(st>=et){              
                  alert("請假開始的時間不能大於或等於請假結束時間");
                  return false;
              }
          }
      }
    function applySubmit(){
        var falg=checkApplyForm();
        if(falg==false){
            return false;
        }
        param=$("#applyForm").serialize();//ajax form序列化參數,根據name取值,根據表單的id進行參數序列化
        var url=contextPath+"/qwsq/addData.action";
        SubmitApply(param,url);
    }
    function SubmitApply(param,url){  
        //alert(param);  
        $.ajax({
            url:url,
            type:"post",
            data:param,
            dataType:"json",
            error:function(XMLHttpRequest,textStatus,errorThrown){
                //alert("--"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown)
            },
            success:function(data){
            //如果後臺傳送的是list集合就進行循環 var i=0;i<data.length;i++
            // var du=data[i];//對象數組
            //alert(du.id);//對象值
                if(data==1){
                    alert("申請表提交成功!");
                }
                else{
                    alert("申請表提交失敗!");
                }
            }//success
            
        })//ajax
    }//函數
    //同系統時間比較
      function getSysdate(calender,time){
          var now = new Date();
          var year=now.getFullYear();    
        var month = now.getMonth()+1 > 9?now.getMonth()+1:'0'+(now.getMonth()+1);    
        var day = now.getDate()+1 > 9?now.getDate():'0'+now.getDate();    
          var hours=now.getHours()+1>9?now.getHours():'0'+(now.getHours()+1);    
          var minutes=now.getMinutes()+1>9?now.getMinutes():'0'+(now.getMinutes());
        var strdate =year+"-"+month+"-"+day;
        strdate=strdate.substring(0,4)+strdate.substring(5,7)+strdate.substring(8,10)
        var strtime=hours+"-"+minutes;    
        strtime=strtime.substring(0,2)+strtime.substring(3,5);
        var flag=false;
        if(calender>strdate){
            flag= true;
        }else if(calender=strdate){
            if(time>strtime){
                flag=true;
            }
        }
        return flag;
      }
    //下拉列表框賦值
     function initSchedTime(){         
         var appSTimeObj=$("#appSTime");
         var appETimeObj=$("#appETime");
         for(var i=0;i<24;i++){
             var hour=i;
             if(i<10){
                 hour="0"+i;
             }
             var html1="<option value='"+hour+"00'>"+hour+":00</option>";
            var html2="<option value='"+hour+"30'>"+hour+":30</option>";         
             appSTimeObj.append(html1);
             appSTimeObj.append(html2);
             appETimeObj.append(html1);
             appETimeObj.append(html2);
         }
     }
    </script>
  </head>  
  <body>
  <input type="hidden" value="${pageContext.request.contextPath} id="contextPath">
  <center>
          <form id="applyForm">
          <table  border="1" align="center" >
              <tr colspan="2"><h2>請假申請表(Ajax提交)</h2></tr>
              <tr>
                  <td>
                      請假類型:
                  </td>             
                  <td>
                      <input type="radio" name="dutyBean.apptype" checked="checked" value="0" οnclick="onchage(this.value)">請假&nbsp;&nbsp;
                      <input type="radio" name="dutyBean.apptype" value="1" οnclick="onchage(this.value)" >出差&nbsp;&nbsp;
                      <input type="radio" name="dutyBean.apptype" value="2" οnclick="onchage(this.value)"/>培訓
                  </td>
              </tr>
              <tr >
                  <td>事由:</td>
                  <td>
                      <textarea rows="5" cols="40" id="appreseon" name="dutyBean.appresson"></textarea>
                  </td>
              </tr>
              <tr >
                  <td style="DISPLAY: none" id="p1">出差地點:</td>
                  <td style="DISPLAY: none" id="p2">培訓地點:</td>
                  <td style="DISPLAY: none" id="p3">
                      <input type="text" id="appplace" name="dutyBean.appplace"/>
                  </td>
              </tr>              
              <tr>
                  <td>
                      請選擇開始日期:
                  </td>
                  <td>                  
                      <input type="text" id="startcalender" name="startcalender" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/>
                      <select id="appSTime" name="dutyBean.starttime"></select>
                  </td>
              </tr>
              <tr>
                  <td>
                      請假結束日期:
                  </td>
                  <td>
                      <input type="text" id="endcalender" name="endcalender" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/>
                      <select id="appETime" name="dutyBean.endtime"></select>        
                  </td>
              </tr>
              <tr>
                  <td colspan="2" >
                      <!-- ajax提交button類型不能爲submit,爲submit的話ajax提交一次,又再次進行提交,有刷新效果,即沒有達到ajax效果 -->
                      <!-- 驗證表單需要使用return 方法名()來進行驗證,未驗證成功不能提交 -->
                      <input type="button" value="提交" οnclick="return applySubmit()"/>&nbsp;&nbsp;
                      <input type="reset" value="取消"/>
                  </td>
              </tr>
          </table>  
          </form>
  </center>
  </body>
</html>

dutyApply.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
  <script>
      var maxpagesize=1;//最大頁數,初始定義爲1
      //alert("maxpagesize="+maxpagesize);
      var contextPath=$("#contextPath").val();
     $(function(){
         init();
         
     })
     //初始化方法
     function init(){         
         //alert("hello world!");     
         var url=contextPath+"/qwsq/queryDutyList.action";
         var param="";
         var tb=$("#dutyApply");
         addDutyApplTableData(tb,url,param);
         initSchedTime();
     }     
     //初始化數據,表頭固定加<thread>表頭</thread>,<tbody>數據</tbody>
     function addDutyApplTableData(tb,url,param){
         //alert("分頁參數2"+param);
         var html="";
         html+="<tbody>"        
         $.ajax({
             url:url,
             type:"post",
             data:param,//記住,data爲傳送的參數
             dataType:"json",
             error:function(XMLHttpRequest,textStatus,errorThrown){
                     //alert("========"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown);
             },
             success:function(data){
                 //alert("currentPage=:"+data.currentPage)//進行分頁封裝後,彈出當前頁
                 maxpagesize=data.totalPage;
                 //alert("最大頁數:"+maxpagesize);
                 //alert(data.totalCount);//打印記錄行數
                 if(data.totalCount==0){                         
                         html+="<tr><th colspan='12' align='left'>您好,沒有符合條件的記錄,請重置搜索條件</th></tr></tbody>";
                         tb.append(html);
                         //alert("您好,沒有符合條件的記錄,請重置搜索條件");
                 }
                 $.each(data.datas,function(i,du){                                                          
                     //alert(du.agreetime)                                  
                     html+="<tr>";
                     html+="<th>"+du.id+"</th>";
                     html+="<th>"+du.startcalender+"</th>";
                     html+="<th>"+du.starttime+"</th>";
                     html+="<th>"+du.endcalender+"</th>";
                     html+="<th>"+du.endtime+"</th>";                     
                     if(du.apptype==0){
                         html+="<th>請假</th>";             
                     }else if(du.apptype==1){
                        html+="<th>出差</th>";             
                     }else if(du.apptype==2){
                        html+="<th>培訓</th>";     
                     }                         
                     html+="<th>"+du.apptime+"</th>";                 
                     if(du.isagree==0){
                         html+="<th>未批准</th>";
                     }else if(du.isagree==1){
                         html+="<th>已批准</th>";
                     }else if(du.isagree==2){
                         html+="<th>不批准</th>";
                     }                                         
                     html+="<th>"+du.appresson+"</th>";
                     html+="<th>"+du.appplace+"</th>";
                     //如果isagree==1設置button爲不可用
                     if(du.isagree==1){
                         html+="<th><input type='button' value='批准'  disabled='disabled' οnclick='agree("+du.id+")'/></th>";
                     }else{
                         html+="<th><input type='button' value='批准' οnclick='agree("+du.id+")'/></th>";
                     }
                     html+="<th><input type='button' value='刪除' οnclick='del("+du.id+")'/></th>";
                     html+="</tr>";        
                     
                 });//.each循環結束
                 //分頁
                 html+="<tr>";
                 html+="<th colspan='12'>當前頁"+data.currentPage;
                 html+="&nbsp;&nbsp;&nbsp;&nbsp共有"+data.totalPage+"頁&nbsp;&nbsp;&nbsp;&nbsp;";
                 //alert("共有多少頁:"+data.totalPage);
                 html+="<a οnclick='paging(1);' href='javascript:void(0);'>首頁</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 if(data.currentPage>1){
                     html+="<a οnclick='paging("+(data.currentPage-1)+");' href='javascript:void(0);'>上一頁</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }else{
                     html+="上一頁&nbsp;&nbsp;&nbsp;&nbsp;";
                 }                 
                 if(data.currentPage<data.totalPage){
                     html+="<a οnclick='paging("+(data.currentPage+1)+");' href='javascript:void(0);'>下一頁</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }else{
                     html+="下一頁&nbsp;&nbsp;&nbsp;&nbsp;";
                 }     
                 if(data.currentPage<data.totalPage){
                     html+="<a οnclick='paging("+(data.totalPage)+");' href='javascript:void(0);'>尾頁</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }else{
                     html+="尾頁&nbsp;&nbsp;&nbsp;&nbsp;";
                 }
                 html+="<input type='text' id='page' size='1'οnkeypress='EnterPress(event)'/>"+"頁&nbsp;&nbsp;"+"<input type='button' value='跳轉' οnclick='goPage()'/>";        
                 html+="</th>";
                 html+="</tr>";
                 html+="</tbody>";
                 tb.append(html);
             }//success
         })//ajax
         
     };//函數
     function EnterPress(e){ //傳入 event
        var e = e || window.event;
        if(e.keyCode == 13){     
        //alert($("#page").val());
        //alert("最大頁數:"+$("#maxpagesize").val());
            if(valPagesize($("#page").val())){
                 paging($("#page").val());
            }
        }
    }
    //跳轉
    function goPage(){    
        //頁數合法進行分頁    
        if(valPagesize($("#page").val())==true){
         paging($("#page").val());
        }
    }
    //判斷是否合法頁數
    function valPagesize(size){
        if(size>=1&&size<=maxpagesize){
            return true;
        }else if(size<1){
            alert("頁不能小於1");
            $("#page").focus();
            return false;
        }else if(size>maxpagesize){
            alert("輸入的頁數不能大於最大頁數");
            $("#page").focus();
            return false;
        }else{
            alert("輸入的頁數不合法");
            $("#page").focus();
            return false;
        }
    }
    //分頁
     function paging(param){         
         var param="pageInfo.currentPage="+param+"&currentPage="+param;
         //alert("分頁參數 :"+param)         
         var tb=$("#dutyApply");
         tb.html("");//清空內容                 
        addDutyApplyTableHead();//添加表頭
        var url=contextPath+"/qwsq/queryDutyList.action";
        addDutyApplTableData(tb,url,param);

     }
     //刪除
     function del(id){
         //alert(id);
         var id=id;
         var url=contextPath+"/qwsq/deleteData.action";
         save(id,url);
     }
     //批准
     function agree(id){
         //alert(id);
         var id=id;
         var url=contextPath+"/qwsq/updateData.action";
         save(id,url);
     }
     //修改,刪除
     function save(id,url){
         if(confirm("確定要對記錄進行修改嗎?")){
         //多個參數爲:param="id="+id+"&id2="+id2+.....
             var param="dutyBean.id="+id;
             $.ajax({
                 url:url,
                 type:"post",
                 data:param,
                 error:function(XMLHttpRequest,textStatus,errorThrown){
                     //alert("========"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown);//彈出信息
                 },
                 success:function(data){
                     if(data==1){
                         alert("操作成功!");
                     }else{
                         alert("操作失敗!");
                     }
                     //由於ajax是異步,要把顯示的數據寫在操作成功后里面,即success:function(data){執行的操作}
                     var tb=$("#dutyApply");    
                     tb.html("");                 
                     addDutyApplyTableHead();//添加表頭
                     var url=contextPath+"/qwsq/queryDutyList.action";
                     var param="";
                     addDutyApplTableData(tb,url,param);
                 }
                 
             })//ajax
             
         }//confirm
         
     }//函數
     //生成表頭
     function addDutyApplyTableHead(){
         var tb=$("#dutyApply");
         //爲了使表頭固定,這是先加<thread></thread>
         tb.append("<thread align='center'>")
         .append("<tr>")
         .append("<td>ID</td>")
         .append("<td>開始日期</td>")
         .append("<td>開始時間</td>")
         .append("<td>結束日期</td>")
         .append("<td>結束時間</td>")
         .append("<td>請假類型</td>")         
         .append("<td>申請時間</td>")     
         .append("<td>是否批准</td>")
         .append("<td>請假事由</td>")
         .append("<td>地點</td>")
         .append("<td>審覈批准</td>")
         .append("<td>管理</td>")
         .append("</tr>")
         .append("</thread>");
     }
     //搜索
     function search(){
         var tb=$("#dutyApply");
         var param=$("#searchForm").serialize();//表單參數序列化
         tb.html("");
        addDutyApplyTableHead();            
         var url=contextPath+"/qwsq/queryDutyList.action";         
         var tb=$("#dutyApply");
         //alert("============參數===========:"+param);
         addDutyApplTableData(tb,url,param);
     }
     //下拉列表框賦值
     function initSchedTime(){
         var sTimeObj=$("#sTime");
         var eTimeObj=$("#eTime");
         var appSTimeObj=$("#appSTime");
         var appETimeObj=$("#appETime");
         for(var i=0;i<24;i++){
             var hour=i;
             if(i<10){
                 hour="0"+i;
             }
             var html1="<option value='"+hour+"00'>"+hour+":00</option>";
            var html2="<option value='"+hour+"30'>"+hour+":30</option>";
             sTimeObj.append(html1);
             sTimeObj.append(html2);
             eTimeObj.append(html1);
             eTimeObj.append(html2);
             appSTimeObj.append(html1);
             appSTimeObj.append(html2);
             appETimeObj.append(html1);
             appETimeObj.append(html2);
         }
     }
  </script>
  </head>
 
  <body>
      <!-- 用來獲取工程的根目錄,需要用的名稱都使用對象名.屬性名,充分利用Struts2面向對象的功能 -->
      <input type="hidden" value="${pageContext.request.contextPath} id="contextPath">
      <center>
      <h2>Ajax進行刪除更新分頁顯示頁面(JSP+Struts2+Poolman)</h2>
      <form id="searchForm">
          <table  width="1024px" >
              <tr>
                  <td>請假類型</td>
                  <td>
                      <select name="dutyBean.apptype" >
                          <option value="0">請假</option>
                          <option value="1">出差</option>
                          <option value="2">培訓</option>
                      </select>
                  </td>
                  <td>審覈批准</td>
                  <td>
                      <select name="dutyBean.isagree">
                          <option value="0">未批准</option>
                          <option value="1">已批准</option>
                          <option value="2">不批准</option>
                      </select>
                  </td>
                  <td align="center">
                      <input type="button" id="btnSeach" value="查詢" οnclick="search()"/>&nbsp;&nbsp;
                      <input type="reset" value="重置"/>
                  </td>
                  <td width="500px">
                  </td>
              </tr>
          </table>
      </form>
      <!-- 在這裏可以定義table的樣式 -->
    <table id="dutyApply" border="1" align="center" width="1024px">
        <tr>
            <td>ID</td>
             <td>開始日期</td>
             <td>開始時間</td>
             <td>結束日期</td>
             <td>結束時間</td>
             <td>請假類型</td>
             <td>申請時間</td>
             <td>是否批准</td>
             <td>請假事由</td>
             <td>地點</td>
             <td>審覈批准</td>
             <td>管理</td>
         </tr>
    </table>
    </center>
  </body>
</html>
C:

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="qwsq" extends="default" namespace="/qwsq">
        <action name="*"
            class="com.chinacreator.qwgl.action.DutyApplyAction"
            method="{1}">
        </action>
    </package>
</struts>

DutyApplyAction

public class DutyApplyAction extends PaginationAction{    
    private static final long serialVersionUID = 4712604081209033471L;
    @SuppressWarnings("unused")
    private static DutyApplyService dutyService=new DutyApplyService();
    private DutyApplyBean dutyBean=new DutyApplyBean();    
    private PageInfo pageInfo=new PageInfo();    
    private String startcalender;
    private String endcalender;
    public PageInfo getPageInfo() {
        return pageInfo;
    }
    public void setPageInfo(PageInfo pageInfo) {
        this.pageInfo = pageInfo;
    }    
    public DutyApplyBean getDutyBean() {
        return dutyBean;
    }
    public void setDutyBean(DutyApplyBean dutyBean) {
        this.dutyBean = dutyBean;
    }        
    public String getStartcalender() {
        return startcalender;
    }
    public void setStartcalender(String startcalender) {
        this.startcalender = startcalender;
    }
    public String getEndcalender() {
        return endcalender;
    }
    public void setEndcalender(String endcalender) {
        this.endcalender = endcalender;
    }
    public void queryDutyList(){    
        pageInfo = this.getPageInfo();    
        try {            
            PageResultInfo<DutyApplyBean> resultList = dutyService.queryDutyApplyList(pageInfo, dutyBean);
            this.responseWrite(resultList);//向頁面輸出對象
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void deleteData(){
        try{
            dutyService.delDutyApply(dutyBean.getId());
            returnValue("1");
        }catch(Exception e){
            returnValue("0");
            e.printStackTrace();            
        }
    }
    public void updateData(){
        try{
            dutyBean.setIsagree(1);
            dutyService.updateDutyApplyInfo(dutyBean);
            returnValue("1");
        }catch(Exception e){
            returnValue("0");
            e.printStackTrace();
        }
    }
    public void addData(){
        System.out.println("apptype:"+dutyBean.getApptype());
        String scalender=dutyService.substr(startcalender);
        String ecalender=dutyService.substr(endcalender);
        if(dutyService.isDate(scalender, dutyBean.getStarttime())&&dutyService.isDate(ecalender, dutyBean.getEndtime())){
            if(dutyService.isLegal(scalender, ecalender, dutyBean.getStarttime(), dutyBean.getEndtime())){
                try{
                    dutyBean.setStartcalender(dutyService.strToNum(scalender));
                    dutyBean.setEndcalender(dutyService.strToNum(ecalender));
                    dutyService.addDutyApply(dutyBean);            
                    
                }catch(Exception e){
                    returnValue("0");//失敗爲0 ajax返回值
                    e.printStackTrace();
                }
            }else{
                returnValue("0");//失敗爲0 ajax返回值
                System.out.println("請假開始日期大於或等於請假結束日期");
            }            
        }else{
            returnValue("0");//失敗爲0 ajax返回值
            System.out.println("申請的日期小於或等於當前日期");
        }
        returnValue("1");//成功爲1 ajax返回值
    }
    
}
這個基類Action定義的方法:因爲使用框架,有很東西,這裏只顯示關鍵性代碼:

/**
     * 輸出文本
     * @param object
     * @return
     */
    protected String responseWrite(Object object)
    {
        try {
            String resStr = JSONUtil.serialize(object);
            this.returnValue(resStr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    protected void returnValue(String resStr){
        try
        {
            Object obj = getSession().getServletContext().getAttribute("encoding");
            String encoding = obj != null ? obj.toString() : "UTF-8";
            response.setCharacterEncoding(encoding);
            response.setContentType("text/plain;Charset=" + encoding);
            response.setHeader("Cache-Control", "no-cache");
            LOG.info(resStr);
            response.getWriter().write(resStr);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

用到分頁的action

public class PaginationAction extends BaseAction {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 543834409862081709L;
    
    private PageInfo pageInfo;
    // 當前頁
    private int currentPage = 1;
    
    //每頁顯示多少記錄
    private int pageSize = 10;
    
    public PageInfo getPageInfo() {
        pageInfo = new PageInfo();
        pageInfo.setCurrentPage(currentPage);
        pageInfo.setPageSize(pageSize);
        return pageInfo;
    }
    
    public void setPageInfo(PageInfo pageInfo) {
        this.pageInfo = pageInfo;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    
}

M

業務層

DutyApplyService

package com.chinacreator.qwgl.service;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import javax.transaction.RollbackException;

import org.junit.Test;

import com.chinacreator.code.pages.PageInfo;
import com.chinacreator.code.pages.PageResultInfo;
import com.chinacreator.common.constant.CommonConstant;
import com.chinacreator.qwgl.bean.DutyApplyBean;
import com.chinacreator.qwgl.dao.DutyApplyDao;
import com.frameworkset.orm.transaction.TransactionManager;
public class DutyApplyService implements Serializable{
    private static DutyApplyDao dutyDao=new DutyApplyDao();
    public static PageResultInfo<DutyApplyBean> queryDutyApplyList(PageInfo pageInfo, DutyApplyBean  dutyApplyBean) throws Exception{
        return dutyDao.queryDutyApplyLis(pageInfo, dutyApplyBean);
    }
    public static DutyApplyBean queryDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
        return dutyDao.queryDutyApply(dutyApplyBean);
    }
    public static void delDutyApply(int id){
        TransactionManager tm = new TransactionManager();
        try{
            tm.begin();
            dutyDao.delDutyApply(id);
            tm.commit();
        }catch(Exception e){
            try {
                tm.rollback();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try {
                tm.commit();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
            
        }        
        
    }
    public static  void addDutyApply(DutyApplyBean dutyApplyBean){
        TransactionManager tm = new TransactionManager();
        try{
            tm.begin();
            dutyDao.addDutyApply(dutyApplyBean);
            tm.commit();
        }catch(Exception e){
            try {
                tm.rollback();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try {
                tm.commit();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        
    }
    public static void updateDutyApplyInfo(DutyApplyBean dutyApplyBean){
        TransactionManager tm = new TransactionManager();
        try{
            tm.begin();
            dutyDao.updateDutyApplyInfo(dutyApplyBean);
            tm.commit();
        }catch(Exception e){
            try {
                tm.rollback();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try {
                tm.commit();
            } catch (RollbackException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
        }
        
    }
    //日期字符截斷2011-11-12 20111112
    public String substr(String str){
        if(isNotNull(str)){
            str=str.substring(0,4)+str.substring(5,7)+str.substring(8,10);
        }
        return str;
    }
    //判斷請假開始日期不能大於等於請假結束日期
    public boolean isLegal(String scalender,String ecalender,String stime,String etime){
        boolean falg=false;
        if(strToNum(scalender)<strToNum(ecalender)){
            falg=true;
        }else if(strToNum(scalender)==strToNum(ecalender)){
            if(strToNum(stime)<strToNum(etime)){
                falg=true;
            }
        }
        return falg;
        
    }    
    //判斷用戶選擇的日期時間不能大於當前日期時間
    public boolean isDate(String calender,String time){
          String uDate=calender;
          Calendar cal = Calendar.getInstance();//使用默認時區和語言環境獲得一個日曆。
          java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyyMMddHHmm");          
          String strDate=format.format(Calendar.getInstance().getTime()).toString();
          String sDate=strDate.substring(0,8);
          String stime=strDate.substring(8,12);          
          System.out.println("sdate:"+sDate);
          if(strToNum(uDate)>strToNum(sDate)){
              return true;          
          }else if(strToNum(uDate)==strToNum(sDate)){
              if(strToNum(time)>strToNum(stime)){
                  return true;
             }    
          }    
          return false;
    }
    @Test
    public void testDate(){
        boolean falg=false;
        falg=isDate("20131123","1410");
        if(falg){
            System.out.println("yes");
        }else{
            System.out.println("no");
        }
    }
    @Test
    public void testIsLegal(){
        boolean falg=false;
        falg=isLegal("20111111","20111112" , "2200", "0000");
        if(falg){
            System.out.println("yes");
        }else{
            System.out.println("no");
        }
    }
    //字符轉數字
    public int strToNum(String str){
        int num=0;
        System.out.println(str);
         if(isNotNull(str)){            
             num=Integer.parseInt(str);
         }
        return num;
    }
    //判斷非空
    public boolean isNotNull(String str){
        if(str!=null&&!str.equals("")){
            return true;
        }else{
            return false;
        }
    }

}
Dao持久化層
DutyApplyDao

package com.chinacreator.qwgl.dao;
import java.io.Serializable;

import org.junit.Test;

import com.chinacreator.code.pages.PageInfo;
import com.chinacreator.code.pages.PageResultInfo;
import com.chinacreator.common.constant.CommonConstant;
import com.chinacreator.common.helper.PaginationHelper;
import com.chinacreator.qwgl.bean.DutyApplyBean;
import com.frameworkset.common.poolman.ConfigSQLExecutor;
import com.frameworkset.util.ListInfo;
public class DutyApplyDao implements Serializable{
    private static ConfigSQLExecutor executor = new ConfigSQLExecutor("com/chinacreator/qwgl/dao/qwsq-sql.xml");
    /**
     * 分頁查詢
     * @param pageInfo
     * @param dutyApplyBean
     * @return
     * @throws Exception
     */
    public static PageResultInfo<DutyApplyBean> queryDutyApplyLis(PageInfo pageInfo, DutyApplyBean  dutyApplyBean) throws Exception{
        ListInfo listInfo = executor.queryListInfoBeanWithDBName(
                 DutyApplyBean.class,CommonConstant.DBNAME_XTPT, "queryDutyApplyListInfo",
                pageInfo.getOffset(), pageInfo.getPageSize(),  dutyApplyBean);

        return PaginationHelper.wrapPageResultInfo(pageInfo, listInfo
                .getTotalSize(), listInfo.getDatas());
    }
    /**
     * 根據條件查詢一個Bean信息
     * @param dutyApplyBean
     * @return
     * @throws Exception
     */
    public static DutyApplyBean queryDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
        return executor.queryObjectBeanWithDBName(DutyApplyBean.class,CommonConstant.DBNAME_XTPT, "queryDutyApplyInfo", dutyApplyBean);
    }
    /**
     * 增加信息
     * @param dutyApplyBean
     * @throws Exception
     */
    public static  void addDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
        executor.insertBean(CommonConstant.DBNAME_XTPT, "insertDutyApply", dutyApplyBean);
    }
    /**
     * 刪除信息
     * @param id
     * @throws Exception
     */
    public static void delDutyApply(int id) throws Exception{
        executor.deleteByKeysWithDBName(CommonConstant.DBNAME_XTPT, "deleteDutyApply", id);
    }
    /**
     * 修改用戶信息
     * @param userBean
     * @throws Exception
     */
    public static void updateDutyApplyInfo(DutyApplyBean dutyApplyBean) throws Exception{
        executor.updateBean(CommonConstant.DBNAME_XTPT, "updateDutyApply", dutyApplyBean);
    }
}

qwsq-sql.xml

<?xml version="1.0" encoding="UTF-8"?>
<properties>
    <property id="queryDutyApplyListInfo">
        <![CDATA[
            select id,
                startcalender,
                starttime,
                endcalender,
                endtime,
                apptype,
                appuserid,
                appusername,
                apptime,
                isagree,
                agreeuserid,
                agreeusername,
                agreetime,
                APPRESSON,
                appplace
            from dutyapply
                where 1=1
             #if($isagree && $isagree!=0)
                  and isagree = #[isagree]
              #end
              #if($apptype && $apptype!=0)
                   and apptype = #[apptype]
              #end
              order by id desc
           ]]>
    </property>
        <property id="queryDutyApplyInfo">
        <![CDATA[
            select id,
                startcalender,
                starttime,
                endcalender,
                endtime,
                apptype,
                appuserid,
                appusername,
                apptime,
                isagree,
                agreeuserid,
                agreeusername,
                agreetime,
                APPRESSON,
                appplace
            from dutyapply
            where 1=1
              #if($id && $id!=0))
                  and id = #[id]
              #end
              #if($isagree && $isagree!=0))
                  and agree = #[agree]
              #end
              #if($apptype && $apptype!=0)
                   and casue = #[casue]
              #end        
            
           ]]>
    </property>
    <property id="insertDutyApply">
        <![CDATA[
            insert into
                dutyapply(            
                    id,                
                    startcalender,
                    starttime,
                    endcalender,
                    endtime,
                    apptype,
                    apptime,
                    appuserid,
                    appusername,
                    isagree,
                    agreeuserid,
                    agreeusername,
                    agreetime,
                    appresson,
                    appplace
                )
                values(
                    td_sequence_dutyApply.nextval,                
                    #[startcalender],
                    #[starttime],
                    #[endcalender],
                    #[endtime],
                    #[apptype],    
                    to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),                
                    #[appuserid],
                    #[appusername],
                    #[isagree],
                    #[agreeuserid],
                    #[agreeusername],
                    #[agreetime],
                    #[appresson],
                    #[appplace]
                )
           ]]>
    </property>
    <property id="updateDutyApply">
        <![CDATA[
            update dutyapply
                set agreetime=to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),
                 #if($isagree && $isagree!=0)
                       isagree = #[isagree]
                   #end            
            where id=#[id]
           ]]>
    </property>
    <property id="deleteDutyApply">
        <![CDATA[
            delete from dutyapply where id=?
           ]]>
    </property>
</properties>

業務Bean

DutyApplyBean

package com.chinacreator.qwgl.bean;
public class DutyApplyBean {
    private int id;
    private int startcalender;
    private String starttime;
    private int endcalender;
    private String endtime;
    private int apptype;
    private String apptime;
    private int appuserid;
    private String appusername;
    private int isagree;
    private int agreeuserid;
    private String agreeusername;
    private String agreetime;
    private String appresson;
    private String appplace;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getStartcalender() {
        return startcalender;
    }
    public void setStartcalender(int startcalender) {
        this.startcalender = startcalender;
    }
    public String getStarttime() {
        return starttime;
    }
    public void setStarttime(String starttime) {
        this.starttime = starttime;
    }
    public int getEndcalender() {
        return endcalender;
    }
    public void setEndcalender(int endcalender) {
        this.endcalender = endcalender;
    }
    public String getEndtime() {
        return endtime;
    }
    public void setEndtime(String endtime) {
        this.endtime = endtime;
    }
    public int getApptype() {
        return apptype;
    }
    public void setApptype(int apptype) {
        this.apptype = apptype;
    }
    public int getAppuserid() {
        return appuserid;
    }
    public void setAppuserid(int appuserid) {
        this.appuserid = appuserid;
    }
    public String getAppusername() {
        return appusername;
    }
    public void setAppusername(String appusername) {
        this.appusername = appusername;
    }
    public int getIsagree() {
        return isagree;
    }
    public void setIsagree(int isagree) {
        this.isagree = isagree;
    }
    public int getAgreeuserid() {
        return agreeuserid;
    }
    public void setAgreeuserid(int agreeuserid) {
        this.agreeuserid = agreeuserid;
    }
    public String getAgreeusername() {
        return agreeusername;
    }
    public void setAgreeusername(String agreeusername) {
        this.agreeusername = agreeusername;
    }
    public String getAgreetime() {
        return agreetime;
    }
    public void setAgreetime(String agreetime) {
        this.agreetime = agreetime;
    }
    
    public String getAppresson() {
        return appresson;
    }
    public void setAppresson(String appresson) {
        this.appresson = appresson;
    }
    public String getAppplace() {
        return appplace;
    }
    public void setAppplace(String appplace) {
        this.appplace = appplace;
    }
    public String getApptime() {
        return apptime;
    }
    public void setApptime(String apptime) {
        this.apptime = apptime;
    }
}



發佈了41 篇原創文章 · 獲贊 5 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章