<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.pojos.TbHandler"%>
<%@page import="com.pojos.TbGroup"%>
<%@page import="com.pojos.TbPurview,com.sxy.sms.constant.Constant"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="jslib/mytable/mytable1.1.js" charset="gb2312"></script>
<link type="text/css" rel="stylesheet" href="jslib/mytable/css/mytable.css"/>
<link type="text/css" rel="stylesheet" href="jslib/jquery_pagination/pagination.css"/>
<script type="text/javascript" src="jslib/jquery_pagination/jquery.pagination.js"></script>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<style>
table.mytable{
width: 1108px;
}
</style>
<%-- 查询行程单 --%>
<div id="queryDiv">
<form id="queryForm" class="queryForm">
<table class="queryTable">
<tr>
<td>行程单号</td><td><input type="text" id="tripNumber" name="tripNumber" class="isForm"/></td>
<td>电子机票号</td><td><input type="text" name="eTicketNumber" class="isForm"/></td>
<td>操作时间</td><td><input type="text" name="operatorDateTime" class="isForm"
onClick="WdatePicker()"/></td>
</tr>
<c:if test="${!param.isReceive}">
<tr>
<td>录入员</td><td><select id="inputer" name="input.inputClerk.handlerId" class="isForm"><option value=""></option></select></td>
<td>领取员</td><td><select id="receiverSelect" name="receiver.handlerId" class="isForm"><option value=""></option></select></td>
<td>发放员</td><td><select id="sender" name="sender.handlerId" class="isForm"><option value=""></option></select></td>
</tr>
</c:if>
<tr>
<td>录入时间</td><td><input type="text" name="input.inputTime" class="isForm"
onClick="WdatePicker()"/></td>
<td>发放时间</td><td><input type="text" name="sendDateTime" class="isForm"
onClick="WdatePicker()"/></td>
</tr>
<tr>
<td>使用状态</td><td>
<select name="usedState" class="isForm">
<option value=""></option>
<option value="<%=Constant.NORMAL_USED%>"><%=Constant.NORMAL_USED_NAME%></option>
<option value="<%=Constant.BUILD_USED%>"><%=Constant.BUILD_USED_NAME%></option>
<option value="<%=Constant.WASTE_USED%>"><%=Constant.WASTE_USED_NAME%></option>
</select></td>
<td>发放状态</td><td>
<select name="sendState" class="isForm">
<option value=""></option>
<option value="<%=Constant.UN_SEND%>"><%=Constant.UN_SEND_NAME%></option>
<option value="<%=Constant.HAS_SEND%>"><%=Constant.HAS_SEND_NAME%></option>
<option value="<%=Constant.HAS_RECYCLED%>"><%=Constant.HAS_RECYCLED_NAME%></option>
</select></td>
<td><input type="button" value="查询" id="query"/></td>
<td><input type="button" value="重置" id="reset"/></td>
</tr>
</table>
</form>
</div>
<div class="viewResults">
<%
String uri = request.getRequestURI();
uri = uri.substring(uri.lastIndexOf("/"), uri.length());
boolean isSendPage = "/send.jsp".equals(uri);
pageContext.setAttribute("isSendPage",isSendPage);
%>
<table class="mytable">
<thead>
<tr>
<th width="20"><input type="checkbox"/></th>
<c:if test="${hasSendPurview&&isSendPage}">
<th width="48">操作</th>
</c:if>
<th width="40">序</th>
<th width="70"><a xx="tripNumber">行程单号</a></th>
<th width="80"><a xx="eTicketNumber">电子机票号</a></th>
<th width="65"><a xx="usedState">使用状态</a></th>
<th width="65"><a xx="sendState">发放状态</a></th>
<th width="50"><a xx="input.inputClerk.handler">录入员</a></th>
<th width="110"><a xx="input.inputTime">录入时间</a></th>
<th width="100"><a xx="receiver.handler">领取员</a></th>
<th width="55"><a xx="sender.handler">发放员</a></th>
<th width="110"><a xx="sendDateTime">发放时间</a></th>
<th width="60"><a xx="operator">操作员</a></th>
<th width="110"><a xx="operatorDateTime">操作时间</a></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div style="float:left;"><div id="pager" class="pagination" style="float:left;"></div><div style="float:left;font:'宋体';font-size:14px;color:#000;margin-top: 5px;">共<span id="totalNums">0</span>条记录</div></div>
<div style="clear: both;"></div>
<c:if test="${hasSendPurview&&isSendPage}">
<div id="toolbar">
<select id="sendTo"><option value="">选择发送对象</option></select>
<button id="sendTripButton">批量发放</button>
</div>
</c:if>
</div>
<script type="text/javascript">
/*mytable--start*/
var pagesTotal = 0;
alert(${param.isReceive});
$.mytable({
url:"queryTrip.do?p=queryTrip&isSendPage=${isSendPage}&isReceive=${param.isReceive}",
sortCol:['input.inputTime','desc'],
storageSortColAttr:'xx',
afterTableLoad_beforePaginationLoad:function(cfg){
cfg.pagesTotal = pagesTotal;
$('#totalNums').text(pagesTotal);
},
beforeLoad:function(){//mytable查询之前做表单验证
var t1 = $('#tripNumber');
var t2 = $('[name="eTicketNumber"]');
var t3 = $('[name="input.inputTime"]');
var t5 = $('[name="sendDateTime"]');
var r1 = /[0-9]{10,20}/;
var r2 = /[0-9]{12,15}/;
var r3 = /[1-9]{1}[0-9]{3}[-][0-1]{1}[0-9]{1}[-][0-3]{1}[0-9]{1}/;
var e1 = "【行程单号】格式有错,格式为:10~20位的数字,您输入了";
var e2 = "【电子机票号】格式有错,格式为:12~15位的数字,您输入了";
var e3 = "格式为:2011-09-05。";
return validate(
[t1,t2,t3,t5],
[r1,r2,r3,r3],
[e1+t1.val().length+'位。',e2+t2.val().length+'位。','【录入时间】格式有错,'+e3,'【发放时间】格式有错,'+e3]
);
},
toolbar:{
'sendTripButton':function(rows){
var sendTo = $('#sendTo').val();
if(''==sendTo) {
alert("请选择发送对象!");
return;
}
var ids = '';
for(var i = 0; i < rows.length; i++){
ids+=rows[i]+';';
}
$.post("queryTrip.do?p=setSend",{ids:ids,receiver_one:sendTo},function(h){
alert(h);
$("#query").click();
});
}
}
});
/*mytable--end*/
/*显示用户选择框 ---start*/
var inputerV = "<%=Constant.INPUT_TRIP%>";
var receiverV = "<%=Constant.RECEIVE_TRIP%>";
var senderV = "<%=Constant.SEND_TRIP%>";
var selJson = false;//录入员、领取员、发放员的json串,此变量可放入一个公共页面缓存起来
if(selJson){
createOptions($("#inputer"), inputerV);//录入员
createOptions($("#receiverSelect"), receiverV);//领取员
createOptions($("#sender"), senderV);//发放员
createOptions($("#sendTo"), receiverV);//发放对象
} else {
$.post("user.do",{p:"getUsersByPurviewValues", "purviewValues":inputerV+','+receiverV+','+senderV},function(json){
selJson = eval("("+json+")");
createOptions($("#inputer"), inputerV);//录入员
createOptions($("#receiverSelect"), receiverV);//领取员
createOptions($("#sender"), senderV);//发放员
createOptions($("#sendTo"), receiverV);//发放对象
});
}
function createOptions(sel, purviewValue) {
for(var i = 0; i < selJson.length; i++) {
if(purviewValue == selJson[i].purviewValue) {
sel.append("<option value='"+ selJson[i].id +"'>"+selJson[i].username+"</option>");
}
}
}
/*显示用户选择框 ---end*/
</script>
<%-- 查询行程单 --%>
分页 Action 代码:
Java代码
//得到页面传递name值
String orderNum = request.getParameter("orderNum"); // 订单号
String orderStatus = request.getParameter("orderStatus"); // 订单状态
String time = request.getParameter("time"); // 下订单时间
// 定义Map 接收
Map<Object, Object> param = new HashMap<Object, Object>();
param.put("orderNum", orderNum);
param.put("orderStatus", orderStatus);
param.put("time", time);
//注意 map 的键必须是pojo 对象的属性
Nam qneOrderList = qne_OrderService.qneOrderSearchMap(param);
//得到页面传递name值
String orderNum = request.getParameter("orderNum"); // 订单号
String orderStatus = request.getParameter("orderStatus"); // 订单状态
String time = request.getParameter("time"); // 下订单时间
// 定义Map 接收
Map<Object, Object> param = new HashMap<Object, Object>();
param.put("orderNum", orderNum);
param.put("orderStatus", orderStatus);
param.put("time", time);
//注意 map 的键必须是pojo 对象的属性
Nam qneOrderList = qne_OrderService.qneOrderSearchMap(param);
分页Dao 代码:
Java代码
//这个方法你也看得懂是干嘛的
private String getWhereContent2(Map<String, String> param) {
StringBuilder sb = new StringBuilder();
for (Iterator<String> iterator = param.keySet().iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && !"".equals(key)
/*
* && !"col".equals(key) && !"order".equals(key) &&
* !"rowStart".equals(key) && !"pageSize".equals(key)
*/) {
if (param.get(key) != null && !"".equals(param.get(key))) {
if ("orderNum".equals(key) || "orderStatus".equals(key)
|| "flightNum".equals(key) || "cabin".equals(key)
|| "ticketNum".equals(key) || "pnr".equals(key)
|| "linkmanCellPhone".equals(key)
|| "startCity".equals(key) || "endCity".equals(key)
|| "flightCompany".equals(key)|| "voyageType".equals(key)
|| "linkmanCellPhone".equals(key)
) {
sb.append(" t." + key + " = '" + param.get(key)
+ "' and ");
} else {
sb.append(" t." + key + " like '%" + param.get(key)
+ "%' and ");
}
}
}
}
if (!"".equals(sb.toString())) {
sb.insert(0, " where(");
sb.delete(sb.lastIndexOf("and"), sb.length());
sb.append(") ");
}
return sb.toString();
}
@SuppressWarnings("unchecked")
public List qneOrderSearchMap(Map<String, String> param){
System.out.println("---- -----");
if(null==param || param.isEmpty()) {
return null;
}
int rowStart = 0;//开始
int pageSize = 30;//一页显示数
String col = "time";// 按你pojo对象里面的time属性排序
String order = "asc";//按asc 排序
boolean b = rowStart>=0 && pageSize>0;
String w = getWhereContent2(param);
//String orderStr = ((null!=col&&!"".equals(col) && null!=order&&!"".equals(order))?"order by t." + col + " "+order:"");
String hql = "from QNEOrder as t " + w;
//+orderStr;
// String countSql = "select count(*) from QNEOrder as t" + w;
Session session = getSession();
Query query = session.createQuery(hql);
if(b) {
query.setFirstResult(rowStart);
query.setMaxResults(pageSize);
}
List list=query.list();
return list;
}
//这个方法你也看得懂是干嘛的
private String getWhereContent2(Map<String, String> param) {
StringBuilder sb = new StringBuilder();
for (Iterator<String> iterator = param.keySet().iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && !"".equals(key)
/*
* && !"col".equals(key) && !"order".equals(key) &&
* !"rowStart".equals(key) && !"pageSize".equals(key)
*/) {
if (param.get(key) != null && !"".equals(param.get(key))) {
if ("orderNum".equals(key) || "orderStatus".equals(key)
|| "flightNum".equals(key) || "cabin".equals(key)
|| "ticketNum".equals(key) || "pnr".equals(key)
|| "linkmanCellPhone".equals(key)
|| "startCity".equals(key) || "endCity".equals(key)
|| "flightCompany".equals(key)|| "voyageType".equals(key)
|| "linkmanCellPhone".equals(key)
) {
sb.append(" t." + key + " = '" + param.get(key)
+ "' and ");
} else {
sb.append(" t." + key + " like '%" + param.get(key)
+ "%' and ");
}
}
}
}
if (!"".equals(sb.toString())) {
sb.insert(0, " where(");
sb.delete(sb.lastIndexOf("and"), sb.length());
sb.append(") ");
}
return sb.toString();
}
@SuppressWarnings("unchecked")
public List qneOrderSearchMap(Map<String, String> param){
System.out.println("---- -----");
if(null==param || param.isEmpty()) {
return null;
}
int rowStart = 0;//开始
int pageSize = 30;//一页显示数
String col = "time";// 按你pojo对象里面的time属性排序
String order = "asc";//按asc 排序
boolean b = rowStart>=0 && pageSize>0;
String w = getWhereContent2(param);
//String orderStr = ((null!=col&&!"".equals(col) && null!=order&&!"".equals(order))?"order by t." + col + " "+order:"");
String hql = "from QNEOrder as t " + w;
//+orderStr;
// String countSql = "select count(*) from QNEOrder as t" + w;
Session session = getSession();
Query query = session.createQuery(hql);
if(b) {
query.setFirstResult(rowStart);
query.setMaxResults(pageSize);
}
List list=query.list();
return list;
}
分页 一个接收查询结果的jsp 其中内容我是以 :
引用
<tr><td>ss</td></tr> <!--这种格式存储的-->
<script>
pagesTotal = ${sum}; // 得到后台处理的最大条数把它传给show.jsp页面 </script>
先说到这儿,分页就可以实现了,而已还有ajax 获取值绑定在select中哦。
ajax 获取值绑定在select中用到的Action方法:
Java代码
public ActionForward getUsersByPurviewValues(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String pvs = request.getParameter("purviewValues");
String[] pvArr = null;
if(pvs != null) {
pvArr = pvs.split(",");
}
String json = iUserSetService.getUsersByPurviewValues(pvArr);
PrintWriter pw = response.getWriter();
pw.print(json);
pw.close();
return null;
}
public ActionForward getUsersByPurviewValues(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String pvs = request.getParameter("purviewValues");
String[] pvArr = null;
if(pvs != null) {
pvArr = pvs.split(",");
}
String json = iUserSetService.getUsersByPurviewValues(pvArr);
PrintWriter pw = response.getWriter();
pw.print(json);
pw.close();
return null;
}
ajax 获取值绑定在select中用到的Dao方法:
Java代码
/**
* 通过权限值得到用户json串
* @param pvArr权限值数组
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
public String getUsersByPurviewValues2(String[] pvArr) throws Exception {
String orS = MyUtils.getOrStr(pvArr, "p.value", true);
String temp = orS.length()>0?" WHERE "+orS:"";
String sql ="SELECT"+
" h.handlerID,h.name,p.value "+
"FROM "+
" tb_handler h "+
" INNER JOIN tb_group g ON h.group_id=g.id "+
" LEFT OUTER JOIN tb_group_purview gp ON g.id=gp.group_id "+
" INNER JOIN tb_purview p ON p.id=gp.purview_id "+
temp+
"UNION "+
"SELECT "+
" h.handlerID,h.name,p.value "+
"FROM "+
" tb_handler h "+
" LEFT OUTER JOIN tb_personal_purview pp ON h.handlerID=pp.hanlder_id "+
" INNER JOIN tb_purview p ON p.id=pp.purview_id "+
temp;
Session session = getSession();
List l = session.createSQLQuery(sql).list();
StringBuilder sb = new StringBuilder();
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
Object[] o = (Object[]) iterator.next();
sb.append("{id:'"+ o[0] +"',username:'"+o[1]+"',purviewValue:'"+o[2]+"'},");
}
if(!"".equals(sb.toString())) {
sb.delete(sb.lastIndexOf(","), sb.length());
sb.insert(0, "[");
sb.append("]");
}
return sb.toString();
}
<%@page import="com.pojos.TbHandler"%>
<%@page import="com.pojos.TbGroup"%>
<%@page import="com.pojos.TbPurview,com.sxy.sms.constant.Constant"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="jslib/mytable/mytable1.1.js" charset="gb2312"></script>
<link type="text/css" rel="stylesheet" href="jslib/mytable/css/mytable.css"/>
<link type="text/css" rel="stylesheet" href="jslib/jquery_pagination/pagination.css"/>
<script type="text/javascript" src="jslib/jquery_pagination/jquery.pagination.js"></script>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<style>
table.mytable{
width: 1108px;
}
</style>
<%-- 查询行程单 --%>
<div id="queryDiv">
<form id="queryForm" class="queryForm">
<table class="queryTable">
<tr>
<td>行程单号</td><td><input type="text" id="tripNumber" name="tripNumber" class="isForm"/></td>
<td>电子机票号</td><td><input type="text" name="eTicketNumber" class="isForm"/></td>
<td>操作时间</td><td><input type="text" name="operatorDateTime" class="isForm"
onClick="WdatePicker()"/></td>
</tr>
<c:if test="${!param.isReceive}">
<tr>
<td>录入员</td><td><select id="inputer" name="input.inputClerk.handlerId" class="isForm"><option value=""></option></select></td>
<td>领取员</td><td><select id="receiverSelect" name="receiver.handlerId" class="isForm"><option value=""></option></select></td>
<td>发放员</td><td><select id="sender" name="sender.handlerId" class="isForm"><option value=""></option></select></td>
</tr>
</c:if>
<tr>
<td>录入时间</td><td><input type="text" name="input.inputTime" class="isForm"
onClick="WdatePicker()"/></td>
<td>发放时间</td><td><input type="text" name="sendDateTime" class="isForm"
onClick="WdatePicker()"/></td>
</tr>
<tr>
<td>使用状态</td><td>
<select name="usedState" class="isForm">
<option value=""></option>
<option value="<%=Constant.NORMAL_USED%>"><%=Constant.NORMAL_USED_NAME%></option>
<option value="<%=Constant.BUILD_USED%>"><%=Constant.BUILD_USED_NAME%></option>
<option value="<%=Constant.WASTE_USED%>"><%=Constant.WASTE_USED_NAME%></option>
</select></td>
<td>发放状态</td><td>
<select name="sendState" class="isForm">
<option value=""></option>
<option value="<%=Constant.UN_SEND%>"><%=Constant.UN_SEND_NAME%></option>
<option value="<%=Constant.HAS_SEND%>"><%=Constant.HAS_SEND_NAME%></option>
<option value="<%=Constant.HAS_RECYCLED%>"><%=Constant.HAS_RECYCLED_NAME%></option>
</select></td>
<td><input type="button" value="查询" id="query"/></td>
<td><input type="button" value="重置" id="reset"/></td>
</tr>
</table>
</form>
</div>
<div class="viewResults">
<%
String uri = request.getRequestURI();
uri = uri.substring(uri.lastIndexOf("/"), uri.length());
boolean isSendPage = "/send.jsp".equals(uri);
pageContext.setAttribute("isSendPage",isSendPage);
%>
<table class="mytable">
<thead>
<tr>
<th width="20"><input type="checkbox"/></th>
<c:if test="${hasSendPurview&&isSendPage}">
<th width="48">操作</th>
</c:if>
<th width="40">序</th>
<th width="70"><a xx="tripNumber">行程单号</a></th>
<th width="80"><a xx="eTicketNumber">电子机票号</a></th>
<th width="65"><a xx="usedState">使用状态</a></th>
<th width="65"><a xx="sendState">发放状态</a></th>
<th width="50"><a xx="input.inputClerk.handler">录入员</a></th>
<th width="110"><a xx="input.inputTime">录入时间</a></th>
<th width="100"><a xx="receiver.handler">领取员</a></th>
<th width="55"><a xx="sender.handler">发放员</a></th>
<th width="110"><a xx="sendDateTime">发放时间</a></th>
<th width="60"><a xx="operator">操作员</a></th>
<th width="110"><a xx="operatorDateTime">操作时间</a></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div style="float:left;"><div id="pager" class="pagination" style="float:left;"></div><div style="float:left;font:'宋体';font-size:14px;color:#000;margin-top: 5px;">共<span id="totalNums">0</span>条记录</div></div>
<div style="clear: both;"></div>
<c:if test="${hasSendPurview&&isSendPage}">
<div id="toolbar">
<select id="sendTo"><option value="">选择发送对象</option></select>
<button id="sendTripButton">批量发放</button>
</div>
</c:if>
</div>
<script type="text/javascript">
/*mytable--start*/
var pagesTotal = 0;
alert(${param.isReceive});
$.mytable({
url:"queryTrip.do?p=queryTrip&isSendPage=${isSendPage}&isReceive=${param.isReceive}",
sortCol:['input.inputTime','desc'],
storageSortColAttr:'xx',
afterTableLoad_beforePaginationLoad:function(cfg){
cfg.pagesTotal = pagesTotal;
$('#totalNums').text(pagesTotal);
},
beforeLoad:function(){//mytable查询之前做表单验证
var t1 = $('#tripNumber');
var t2 = $('[name="eTicketNumber"]');
var t3 = $('[name="input.inputTime"]');
var t5 = $('[name="sendDateTime"]');
var r1 = /[0-9]{10,20}/;
var r2 = /[0-9]{12,15}/;
var r3 = /[1-9]{1}[0-9]{3}[-][0-1]{1}[0-9]{1}[-][0-3]{1}[0-9]{1}/;
var e1 = "【行程单号】格式有错,格式为:10~20位的数字,您输入了";
var e2 = "【电子机票号】格式有错,格式为:12~15位的数字,您输入了";
var e3 = "格式为:2011-09-05。";
return validate(
[t1,t2,t3,t5],
[r1,r2,r3,r3],
[e1+t1.val().length+'位。',e2+t2.val().length+'位。','【录入时间】格式有错,'+e3,'【发放时间】格式有错,'+e3]
);
},
toolbar:{
'sendTripButton':function(rows){
var sendTo = $('#sendTo').val();
if(''==sendTo) {
alert("请选择发送对象!");
return;
}
var ids = '';
for(var i = 0; i < rows.length; i++){
ids+=rows[i]+';';
}
$.post("queryTrip.do?p=setSend",{ids:ids,receiver_one:sendTo},function(h){
alert(h);
$("#query").click();
});
}
}
});
/*mytable--end*/
/*显示用户选择框 ---start*/
var inputerV = "<%=Constant.INPUT_TRIP%>";
var receiverV = "<%=Constant.RECEIVE_TRIP%>";
var senderV = "<%=Constant.SEND_TRIP%>";
var selJson = false;//录入员、领取员、发放员的json串,此变量可放入一个公共页面缓存起来
if(selJson){
createOptions($("#inputer"), inputerV);//录入员
createOptions($("#receiverSelect"), receiverV);//领取员
createOptions($("#sender"), senderV);//发放员
createOptions($("#sendTo"), receiverV);//发放对象
} else {
$.post("user.do",{p:"getUsersByPurviewValues", "purviewValues":inputerV+','+receiverV+','+senderV},function(json){
selJson = eval("("+json+")");
createOptions($("#inputer"), inputerV);//录入员
createOptions($("#receiverSelect"), receiverV);//领取员
createOptions($("#sender"), senderV);//发放员
createOptions($("#sendTo"), receiverV);//发放对象
});
}
function createOptions(sel, purviewValue) {
for(var i = 0; i < selJson.length; i++) {
if(purviewValue == selJson[i].purviewValue) {
sel.append("<option value='"+ selJson[i].id +"'>"+selJson[i].username+"</option>");
}
}
}
/*显示用户选择框 ---end*/
</script>
<%-- 查询行程单 --%>
分页 Action 代码:
Java代码
//得到页面传递name值
String orderNum = request.getParameter("orderNum"); // 订单号
String orderStatus = request.getParameter("orderStatus"); // 订单状态
String time = request.getParameter("time"); // 下订单时间
// 定义Map 接收
Map<Object, Object> param = new HashMap<Object, Object>();
param.put("orderNum", orderNum);
param.put("orderStatus", orderStatus);
param.put("time", time);
//注意 map 的键必须是pojo 对象的属性
Nam qneOrderList = qne_OrderService.qneOrderSearchMap(param);
//得到页面传递name值
String orderNum = request.getParameter("orderNum"); // 订单号
String orderStatus = request.getParameter("orderStatus"); // 订单状态
String time = request.getParameter("time"); // 下订单时间
// 定义Map 接收
Map<Object, Object> param = new HashMap<Object, Object>();
param.put("orderNum", orderNum);
param.put("orderStatus", orderStatus);
param.put("time", time);
//注意 map 的键必须是pojo 对象的属性
Nam qneOrderList = qne_OrderService.qneOrderSearchMap(param);
分页Dao 代码:
Java代码
//这个方法你也看得懂是干嘛的
private String getWhereContent2(Map<String, String> param) {
StringBuilder sb = new StringBuilder();
for (Iterator<String> iterator = param.keySet().iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && !"".equals(key)
/*
* && !"col".equals(key) && !"order".equals(key) &&
* !"rowStart".equals(key) && !"pageSize".equals(key)
*/) {
if (param.get(key) != null && !"".equals(param.get(key))) {
if ("orderNum".equals(key) || "orderStatus".equals(key)
|| "flightNum".equals(key) || "cabin".equals(key)
|| "ticketNum".equals(key) || "pnr".equals(key)
|| "linkmanCellPhone".equals(key)
|| "startCity".equals(key) || "endCity".equals(key)
|| "flightCompany".equals(key)|| "voyageType".equals(key)
|| "linkmanCellPhone".equals(key)
) {
sb.append(" t." + key + " = '" + param.get(key)
+ "' and ");
} else {
sb.append(" t." + key + " like '%" + param.get(key)
+ "%' and ");
}
}
}
}
if (!"".equals(sb.toString())) {
sb.insert(0, " where(");
sb.delete(sb.lastIndexOf("and"), sb.length());
sb.append(") ");
}
return sb.toString();
}
@SuppressWarnings("unchecked")
public List qneOrderSearchMap(Map<String, String> param){
System.out.println("---- -----");
if(null==param || param.isEmpty()) {
return null;
}
int rowStart = 0;//开始
int pageSize = 30;//一页显示数
String col = "time";// 按你pojo对象里面的time属性排序
String order = "asc";//按asc 排序
boolean b = rowStart>=0 && pageSize>0;
String w = getWhereContent2(param);
//String orderStr = ((null!=col&&!"".equals(col) && null!=order&&!"".equals(order))?"order by t." + col + " "+order:"");
String hql = "from QNEOrder as t " + w;
//+orderStr;
// String countSql = "select count(*) from QNEOrder as t" + w;
Session session = getSession();
Query query = session.createQuery(hql);
if(b) {
query.setFirstResult(rowStart);
query.setMaxResults(pageSize);
}
List list=query.list();
return list;
}
//这个方法你也看得懂是干嘛的
private String getWhereContent2(Map<String, String> param) {
StringBuilder sb = new StringBuilder();
for (Iterator<String> iterator = param.keySet().iterator(); iterator
.hasNext();) {
String key = iterator.next();
if (key != null && !"".equals(key)
/*
* && !"col".equals(key) && !"order".equals(key) &&
* !"rowStart".equals(key) && !"pageSize".equals(key)
*/) {
if (param.get(key) != null && !"".equals(param.get(key))) {
if ("orderNum".equals(key) || "orderStatus".equals(key)
|| "flightNum".equals(key) || "cabin".equals(key)
|| "ticketNum".equals(key) || "pnr".equals(key)
|| "linkmanCellPhone".equals(key)
|| "startCity".equals(key) || "endCity".equals(key)
|| "flightCompany".equals(key)|| "voyageType".equals(key)
|| "linkmanCellPhone".equals(key)
) {
sb.append(" t." + key + " = '" + param.get(key)
+ "' and ");
} else {
sb.append(" t." + key + " like '%" + param.get(key)
+ "%' and ");
}
}
}
}
if (!"".equals(sb.toString())) {
sb.insert(0, " where(");
sb.delete(sb.lastIndexOf("and"), sb.length());
sb.append(") ");
}
return sb.toString();
}
@SuppressWarnings("unchecked")
public List qneOrderSearchMap(Map<String, String> param){
System.out.println("---- -----");
if(null==param || param.isEmpty()) {
return null;
}
int rowStart = 0;//开始
int pageSize = 30;//一页显示数
String col = "time";// 按你pojo对象里面的time属性排序
String order = "asc";//按asc 排序
boolean b = rowStart>=0 && pageSize>0;
String w = getWhereContent2(param);
//String orderStr = ((null!=col&&!"".equals(col) && null!=order&&!"".equals(order))?"order by t." + col + " "+order:"");
String hql = "from QNEOrder as t " + w;
//+orderStr;
// String countSql = "select count(*) from QNEOrder as t" + w;
Session session = getSession();
Query query = session.createQuery(hql);
if(b) {
query.setFirstResult(rowStart);
query.setMaxResults(pageSize);
}
List list=query.list();
return list;
}
分页 一个接收查询结果的jsp 其中内容我是以 :
引用
<tr><td>ss</td></tr> <!--这种格式存储的-->
<script>
pagesTotal = ${sum}; // 得到后台处理的最大条数把它传给show.jsp页面 </script>
先说到这儿,分页就可以实现了,而已还有ajax 获取值绑定在select中哦。
ajax 获取值绑定在select中用到的Action方法:
Java代码
public ActionForward getUsersByPurviewValues(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String pvs = request.getParameter("purviewValues");
String[] pvArr = null;
if(pvs != null) {
pvArr = pvs.split(",");
}
String json = iUserSetService.getUsersByPurviewValues(pvArr);
PrintWriter pw = response.getWriter();
pw.print(json);
pw.close();
return null;
}
public ActionForward getUsersByPurviewValues(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String pvs = request.getParameter("purviewValues");
String[] pvArr = null;
if(pvs != null) {
pvArr = pvs.split(",");
}
String json = iUserSetService.getUsersByPurviewValues(pvArr);
PrintWriter pw = response.getWriter();
pw.print(json);
pw.close();
return null;
}
ajax 获取值绑定在select中用到的Dao方法:
Java代码
/**
* 通过权限值得到用户json串
* @param pvArr权限值数组
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
public String getUsersByPurviewValues2(String[] pvArr) throws Exception {
String orS = MyUtils.getOrStr(pvArr, "p.value", true);
String temp = orS.length()>0?" WHERE "+orS:"";
String sql ="SELECT"+
" h.handlerID,h.name,p.value "+
"FROM "+
" tb_handler h "+
" INNER JOIN tb_group g ON h.group_id=g.id "+
" LEFT OUTER JOIN tb_group_purview gp ON g.id=gp.group_id "+
" INNER JOIN tb_purview p ON p.id=gp.purview_id "+
temp+
"UNION "+
"SELECT "+
" h.handlerID,h.name,p.value "+
"FROM "+
" tb_handler h "+
" LEFT OUTER JOIN tb_personal_purview pp ON h.handlerID=pp.hanlder_id "+
" INNER JOIN tb_purview p ON p.id=pp.purview_id "+
temp;
Session session = getSession();
List l = session.createSQLQuery(sql).list();
StringBuilder sb = new StringBuilder();
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
Object[] o = (Object[]) iterator.next();
sb.append("{id:'"+ o[0] +"',username:'"+o[1]+"',purviewValue:'"+o[2]+"'},");
}
if(!"".equals(sb.toString())) {
sb.delete(sb.lastIndexOf(","), sb.length());
sb.insert(0, "[");
sb.append("]");
}
return sb.toString();
}