ssm 存儲過程分頁

分頁存儲過程:


CREATE OR REPLACE PROCEDURE prc_query

       (p_tableName        in  varchar2,   --表名

        p_strWhere         in  varchar2,   --查詢條件

        p_orderColumn      in  varchar2,   --排序的列

        p_orderStyle       in  varchar2,   --排序方式

        p_curPage          in out number,  --當前頁

        p_pageSize         in out number,  --每頁顯示記錄條數

        p_totalRecords     out number,     --總記錄數

        p_totalPages       out number,     --總頁數

        v_cur              out pkg_query.cur_query)   --返回的結果集

IS

   v_sql VARCHAR2(1000) := '';      --sql語句

   v_startRecord Number(4);         --開始顯示的記錄條數

   v_endRecord Number(4);           --結束顯示的記錄條數

BEGIN

   --記錄中總記錄條數

   v_sql := 'SELECT TO_NUMBER(COUNT(*)) FROM ' || p_tableName || ' WHERE 1=1';

   IF p_strWhere IS NOT NULL or p_strWhere <> '' THEN

       v_sql := v_sql || p_strWhere;

   END IF;

   EXECUTE IMMEDIATE v_sql INTO p_totalRecords;


   --驗證頁面記錄大小

   IF p_pageSize < 0 THEN

       p_pageSize := 0;

   END IF;


   --根據頁大小計算總頁數

   IF MOD(p_totalRecords,p_pageSize) = 0 THEN

       p_totalPages := p_totalRecords / p_pageSize;

   ELSE

       p_totalPages := p_totalRecords / p_pageSize + 1;

   END IF;


   --驗證頁號

   IF p_curPage < 1 THEN

       p_curPage := 1;

   END IF;

   IF p_curPage > p_totalPages THEN

       p_curPage := p_totalPages;

   END IF;


   --實現分頁查詢

   v_startRecord := (p_curPage - 1) * p_pageSize + 1;

   v_endRecord := p_curPage * p_pageSize;

   v_sql := 'SELECT * FROM (SELECT A.*, rownum r FROM ' ||

            '(SELECT * FROM ' || p_tableName;

   IF p_strWhere IS NOT NULL or p_strWhere <> '' THEN

       v_sql := v_sql || ' WHERE 1=1' || p_strWhere;

   END IF;

   IF p_orderColumn IS NOT NULL or p_orderColumn <> '' THEN

       v_sql := v_sql || ' ORDER BY ' || p_orderColumn || ' ' || p_orderStyle;

   END IF;

   v_sql := v_sql || ') A WHERE rownum <= ' || v_endRecord || ') B WHERE r >= '

            || v_startRecord;

   DBMS_OUTPUT.put_line(v_sql);

   OPEN v_cur FOR v_sql;

   

END prc_query;

controller:


@Controller

@RequestMapping("/userloginLog")

public class UserLoginLogController {

@Autowired

private IUserLoginLogService userLoginLogService;

@RequestMapping("/getAllUser")

public String getAllUser(HttpServletRequest request,HttpServletResponse response,Model model){

try { 

String sql = "";

int pageNo =1;

Map<String, Object> param = new HashMap<String, Object>();

String StrpageNo = request.getParameter("pageNo");

if(StringUtils.isNotBlank(StrpageNo)){

pageNo = Integer.parseInt(StrpageNo);

}

String loginName = request.getParameter("loginName");

String resultCode = request.getParameter("resultCode");

String channelid = request.getParameter("channelid");

String startTime = request.getParameter("startTime");

String endTime = request.getParameter("endTime");

if(StringUtils.isNotBlank(loginName)){

sql+=" and login_name='" + loginName + "'";

model.addAttribute("loginName", loginName);

}

if(StringUtils.isNotBlank(resultCode)){

sql+=" and RESULT_CODE='" + resultCode + "'";

model.addAttribute("resultCode", resultCode);

}

if(StringUtils.isNotBlank(channelid)){

sql+=" and CHANNELID='" + channelid + "'";

model.addAttribute("channelid", channelid);

}

if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime) ){

sql+=" and LOGIN_TIME between to_date('"+startTime+"', 'yyyy-mm-dd hh24:mi:ss') and to_date('"+endTime+"', 'yyyy-mm-dd hh24:mi:ss')";

model.addAttribute("startTime", startTime);

model.addAttribute("endTime", endTime);

}

        param.put("tableName", "TL_USER_LOGIN_LOG");

        param.put("strWhere", sql);

        param.put("curPage", pageNo);

        param.put("pageSize", 20);

        userLoginLogService.getPrAllUser(param);

        //result 爲在mybatis xml文件時 寫的返回結果名

        List<TlUserLoginLog> LoginLogList= (List<TlUserLoginLog>) param.get("result"); 

        int curPage = (Integer) param.get("curPage");

        int totalRecords = (Integer) param.get("totalRecords");

        int totalPages = (Integer) param.get("totalPages");

        model.addAttribute("myPage", curPage);

        model.addAttribute("pageNo", curPage);

        model.addAttribute("totalCount", totalRecords);

        model.addAttribute("totalPage", totalPages);

        model.addAttribute("userLoginLogList", LoginLogList);

return "prTest";

} catch (Exception e) {

e.printStackTrace();

model.addAttribute("InfoMessage",

"獲取信息失敗,異常:" + e.getMessage());

return "result";

 }

 }


}


IUserLoginLogService:


public List<TlUserLoginLog> getPrAllUser(Map map);


UserLoginLogServiceImpl:


@Override

public List<TlUserLoginLog> getPrAllUser(Map map) {

// TODO Auto-generated method stub

return userLoginLogDao.getPrAllUser(map);

}

IUserLoginLogDao:


public List<TlUserLoginLog> getPrAllUser(Map map);


mybitas:

<!-- 調用存儲過程返回結果集 -->

    <select id="getPrAllUser" statementType="CALLABLE" >

        {call prc_query(

        #{tableName,mode=IN,jdbcType=VARCHAR},

        #{strWhere,mode=IN,jdbcType=VARCHAR},

        #{orderColumn,mode=IN,jdbcType=VARCHAR},

        #{orderStyle,mode=IN,jdbcType=VARCHAR},

        #{curPage,mode=IN,jdbcType=INTEGER},

        #{pageSize,mode=IN,jdbcType=INTEGER},

        #{totalRecords,mode=OUT,jdbcType=INTEGER},

        #{totalPages,mode=OUT,jdbcType=INTEGER},

        #{result,mode=OUT,javaType=java.sql.ResultSet,jdbcType=CURSOR,resultMap=com.ai.tyca.dao.IUserLoginLogDao.BaseResultMap}

        )}   

   </select>

JSP:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

    <title>Basic Form - jQuery EasyUI Demo</title>

    <link rel="stylesheet" type="text/css" href="/common/jquery-easyui-1.5.1/themes/default/easyui.css">

    <link rel="stylesheet" type="text/css" href="/common/jquery-easyui-1.5.1/themes/icon.css">

    <script type="text/javascript" src="/common/jquery-easyui-1.5.1/jquery.min.js"></script>

    <script type="text/javascript" src="/common/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="/common/jquery-easyui-1.5.1/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">

 $(function(){

         var pageNo = parseInt($("#currentPageNo").val());

         var totalPage = parseInt($("#totalPage").val());

         if(pageNo == 1 && totalPage == pageNo){

             $("#previous").hide();

             $("#next").hide();

         }else if(pageNo == 1 && totalPage > 1){

             $("#previous").hide();

             $("#next").show();

         }else if(pageNo > 1 && pageNo < totalPage){

             $("#previous").show();

             $("#next").show();

         }else if(pageNo == totalPage && pageNo > 1){

             $("#previous").show();

             $("#next").hide();

         }

         

         $("#previous").click(function(){

             $("#pageNo").val(--pageNo);

             $("#form1").submit();

         });

         $("#next").click(function(){

             $("#pageNo").val(++pageNo);

             $("#form1").submit();

         });

         $("#firstPage").click(function(){

             $("#pageNo").val(1);

             $("#form1").submit();

         });

         $("#lastPage").click(function(){

             $("#pageNo").val(totalPage);

             $("#form1").submit();

         });

         $("#selectPage").change(function(){

             $("#pageNo").val($(this).val());

             $("#form1").submit();

         });

         

         $("#selectPage").val(pageNo);

         

         $("#addItemNoteConfirm").click(function(){

             //textarea可以使用val獲得值

             var notes = $("#itemNote").val();

             $("#notes").val(notes);

             $("#showForm").submit();

         });

         

         $("#goSearch").click(function(){

        var start = $("#startRequestTime").val();

             var end   = $("#endRequestTime").val();

             if(start != null  && end != null && $.trim(start) != '' && $.trim(end) != ''){

                 if(start >= end){

                     alert("開始時間不能大於結束時間!");

                     return false;

                 } 

             }

             $("#form1").submit();

         });

         $("#reset").click(function(){

             $('input').val('');

         });

 

$('#dataID').datagrid({

              onDblClickRow: function(rowIndex) {

               $('#dataID').datagrid('selectRow',rowIndex);

                var currentRow =$("#dataID").datagrid("getSelected");

                $.ajax({

                    type:'post',

                    url:'Security/getSecurity.do',

                    type:"post",

                    dataType:"text",

                    data:{

                        originalxml:currentRow.originalxml

                    },

                    cache:false , 

                    success:function(orgXML){

                        $("#dialogorgxml").textbox('setValue',orgXML);

                    }

                });

                if(currentRow.loginUserType == "01"){

                    var loginUserType = "手機賬號";

                }else if(currentRow.loginUserType == "02"){

                    var loginUserType = "別名賬號";

                }

                if(currentRow.loginAccountType == "01"){

                    var loginAccountType ="個人用戶";

                }else if(currentRow.loginAccountType == "02"){

                    var loginAccountType ="企業用戶";

                }

                $("#dialogName").textbox('setValue',currentRow.loginName);

                $("#dialogTime").textbox('setValue',currentRow.requestTime);

                $("#dialogUserType").textbox('setValue',loginUserType);

                $("#dialogAccountType").textbox('setValue',loginAccountType);

                $("#dialogResult").textbox('setValue',currentRow.result);

                $("#dialogDesc").textbox('setValue',currentRow.resultDesc);

                $("#dialogRspxml").textbox('setValue',currentRow.rspxml);

                $("#dialogChannelid").textbox('setValue',currentRow.channelid);

                $("#dialogorgxml").textbox('setValue',currentRow.originalxml);

                

                $('#roleDialog').show().dialog({ 

                    left:400,

                    top:50,

                    modal : true, 

                    title : '詳細信息', 

                    modal: true, 

                    closable: true, 

                    draggable: true, 

                    width: 550, 

                    height: 580

                    }); 

                }

              });

        });

</script>


</head>

<body>

    <form id="form1" name="form1" action="${basePath}userloginLog/getAllUser.do" method="post">

       <div style="width:100%;height:95%" >

       <div id="p" class="easyui-panel" title="查詢框" style="width:99%;height:100px;"

                data-options="collapsible:true">

           <div style="width:100%;height:100%;">

               <table id="searchId" style="width:100%;height:50px;">

                    <tr>

                        <td>用戶名:</td>

                        <td><input class="easyui-textbox" style="width: 140px;" value="${loginName}" name="loginName" ></input></td>

                        <td>起始時間:</td>

                        <td><input id="startRequestTime" class="easyui-datetimebox" style="width: 140px;" value="${startTime}" name="startTime" ></input></td>

                        <td>結束時間:</td>

                        <td><input id="endRequestTime"   class="easyui-datetimebox" style="width: 140px;" value="${endTime}" name="endTime" ></input></td>

                        <td>請求結果類型:</td>

                        <td>

                           <select id="resultCode" class="easyui-combobox" name="resultCode" style="width:150px">

                               <option value="" selected>可選擇結果類型</option>

                               <option value="0000" <c:if test="${'0000' eq resultCode}">selected</c:if>>成功</option>

                               <option value="8002" <c:if test="${'8002' eq resultCode}">selected</c:if>>密碼錯誤</option>

                               <option value="8008" <c:if test="${'8008' eq resultCode}">selected</c:if>>賬號已鎖定</option>

                               <option value="8001" <c:if test="${'8001' eq resultCode}">selected</c:if>>賬號不存在</option>

                               <option value="9008" <c:if test="${'9008' eq resultCode}">selected</c:if>>簽名驗證錯誤</option>

                               <option value="9006" <c:if test="${'9006' eq resultCode}">selected</c:if>>認證請求報文格式錯誤</option>

                           </select>

                       </td>

                        <td>平臺:</td>

                        <td>

                           <select id="channelid" class="easyui-combobox" name="channelid" style="width:150px">

                               <option value="" selected>可選擇用戶平臺</option>

                               <option value="10001" <c:if test="${'10001' eq channelid}">selected</c:if>>店員獎勵系統</option>

                               <option value="10002" <c:if test="${'10002' eq channelid}">selected</c:if>>直供系統</option>

                               <option value="10003" <c:if test="${'10003' eq channelid}">selected</c:if>>終端信息平臺</option>

                               <option value="10004" <c:if test="${'10004' eq channelid}">selected</c:if>>售後</option>

                               <option value="10005" <c:if test="${'10005' eq channelid}">selected</c:if>>用戶信息管理平臺</option>

                           </select>

                       </td>

                        <td><a id="goSearch" class="easyui-linkbutton" type="submit" iconcls="icon-search" href="javascript:void(0)" onclick="login()">查詢</a></td>

                        <td><a id="reset"    class="easyui-linkbutton" type="reset" iconCls="icon-undo" href="javascript:void(0)" onclick="reset()">重置</a></td>

                    </tr>

                </table>

           </div>

        </div>

        <table id="dataID" class="easyui-datagrid" style="width:99%;height:95%"  

           data-options="singleSelect:true,fitColumns:true,method:'get'">

        <thead>

             <tr>

                  <th data-options="field:'sequence',width:5,align:'center'">序列</th>

                  <th data-options="field:'loginName',width:10,align:'center'">用戶名</th>

                  <th data-options="field:'requestTime',width:13,align:'center'">請求時間</th>

                  <th data-options="field:'resultDesc',width:10,align:'left'">請求結果</th>

                  <th data-options="field:'channelid',width:20,align:'center'">渠道</th>

                  <th data-options="field:'loginUserType',width:10,align:'center',hidden:true">用戶類型</th>

                  <th data-options="field:'loginAccountType',width:10,align:'center',hidden:true">賬號類型</th>

                  <th data-options="field:'originalxml',width:20,align:'left',hidden:true">加密報文</th>

                  <th data-options="field:'rspxml',width:20,align:'right',hidden:true">返回報文</th>

             </tr>

        </thead>

        <tbody>

            <c:forEach items="${userLoginLogList}" var="loginList" varStatus="sequence">

                 <tr>

                    <td>${sequence.count}</td>

                    <td>${loginList.loginName }</td>

                    <td >${loginList.loginTime }</td>

                    <td>${loginList.resultDesc }</td>

                    <c:choose>

                       <c:when test="${'10001' eq loginList.channelid}">  

                        <td>店員獎勵系統</td>

                       </c:when>

                       <c:when test="${'10002' eq loginList.channelid}">  

                        <td>直供系統</td>

                       </c:when>

                       <c:when test="${'10003' eq loginList.channelid}">  

                        <td>終端信息平臺</td>

                       </c:when>

                       <c:when test="${'10004' eq loginList.channelid}">  

                        <td>售後</td>

                       </c:when>

                       <c:when test="${'10005' eq loginList.channelid}">  

                        <td>用戶信息管理平臺</td>

                       </c:when>

                       <c:otherwise> 

                       <td></td>

                       </c:otherwise>

                    </c:choose>

                    <td>${loginList.loginUserType }</td>

                    <td>${loginList.loginAccountType }</td>

                    <td>${loginList.originalxml }</td>

                    <td>${loginList.rspxml }</td>

                </tr>

            </c:forEach>

      </tbody>

    </table>

        <div class="page_c">

            <span class="l inb_a">

            </span>

            <span class="r page">

                <input type="hidden" id="pageNo" name="pageNo" />

                <input type="hidden" value="${totalCount}" id="totalCount" name="totalCount" />

                <input type="hidden" value="${pageNo}" id="currentPageNo" name="currentPageNo" />

                <input type="hidden" value="${totalPage}" id="totalPage" name="totalPage" />

                        共<var id="pagePiece" class="orange">${totalCount}</var>條<var id="pageTotal">${pageNo}/${totalPage}</var>

                <a href="javascript:void(0);" id="firstPage"  >首頁</a>

                <a href="javascript:void(0);" id="previous" class="hidden" title="上一頁">上一頁</a>

                <a href="javascript:void(0);" id="next" class="hidden" title="下一頁">下一頁</a>

                <select id="selectPage" >

                    <c:forEach begin="1" end="${totalPage }" var="myPage">

                        <option value="${myPage }">第${myPage }頁</option>

                    </c:forEach>

                </select>

                 <a href="javascript:void(0);" id="lastPage" >尾頁</a>

            </span>

        </div>

       </div>

    </form>

     <div id="roleDialog" style="display: none;overflow: hidden;"> 

         <table id="detail" cellpadding="5" style="margin-left:20%;margin-top:5%;">

           <tr>

              <td>用戶名:</td>

              <td><input id="dialogName" class="easyui-textbox" style="width: 240px;"  name="loginName" ></input></td>

           </tr>

           <tr>

              <td>請求時間:</td>

              <td><input id="dialogTime" class="easyui-textbox" style="width: 240px;" value="" name="loginName" ></input></td>

           </tr>

           <tr>

              <td>用戶類型:</td>

              <td><input id="dialogUserType" class="easyui-textbox" style="width: 240px;" value="" name="loginUserType" ></input></td>

           </tr>

           <tr>

              <td>賬號類型:</td>

              <td><input id="dialogAccountType" class="easyui-textbox" style="width: 240px;" value="" name="loginAccountType" ></input></td>

           </tr>

           <tr>

              <td>返回結果:</td>

              <td><input id="dialogDesc" class="easyui-textbox" style="width: 240px;" value="" name="loginName" ></input></td>

           </tr>

           <tr>

              <td>平臺系統:</td>

              <td><input id="dialogChannelid" class="easyui-textbox" style="width: 240px;" value="" name="loginName" ></input></td>

           </tr>

           <tr>

              <td>返回報文:</td>

              <td><input id="dialogRspxml"  data-options="multiline:true" class="easyui-textbox" style="width: 240px;height:100px;"  value="" name="loginName" ></input></td>

           </tr>

           <tr>

              <td>解密後報文:</td>

              <td><input id="dialogorgxml"  data-options="multiline:true" class="easyui-textbox" style="width: 240px;height:130px;" value="" name="loginName" ></input></td>

           </tr>

         </table>

    </div>

</body>

</html>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章