struts实战--实现条件查询(利用dbutils)
struts實(shí)現(xiàn)條件查詢(xún)---利用dbutils
一.在list.jsp頁(yè)面修改查詢(xún)組件
?? ??? ?
?? ??? ?是否上傳簡(jiǎn)歷
?? ??? ?<s:select list="#{'1':'有','2':'無(wú)'}" name="isUpload" id="isUpload" headerKey="0" headerValue="--請(qǐng)選擇--"></s:select>
? ?
<%@ page language="java" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s"%> <HTML><HEAD><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css" /><script language="javascript" src="${pageContext.request.contextPath}/js/public.js"></script><script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery-1.4.2.js"></script><script type="text/javascript">function addUser(){window.location.href = "${pageContext.request.contextPath}/user/add.jsp";}$(function(){// 為刪除鏈接 加確認(rèn)效果$(".delLink").click(function(event){var isConfirm = window.confirm("想好了嗎?");if(!isConfirm){// 阻止提交event.preventDefault();}});});</script></HEAD><body><br><s:form action="user_list" namespace="/" method="post" theme="simple" id="Form1" name="Form1"><table cellSpacing="1" cellPadding="0" width="100%" align="center" bgColor="#f5fafe" border="0"><TBODY><tr><td class="ta_01" align="center" bgColor="#afd1f3"><strong>查 詢(xún) 條 件</strong></td></tr><tr><td><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="22" align="center" bgColor="#f5fafe" class="ta_01">用戶姓名</td><td class="ta_01" bgColor="#ffffff"><s:textfield name="userName" size="15" id="Form1_userName" cssClass="bg"/></td><td height="22" align="center" bgColor="#f5fafe" class="ta_01">性別:</td><td class="ta_01" bgColor="#ffffff"><s:select list="{'男','女'}" name="sex" id="sex" headerKey="" headerValue="--選擇性別--"></s:select></td></tr><tr><td height="22" align="center" bgColor="#f5fafe" class="ta_01">學(xué)歷:</td><td class="ta_01" bgColor="#ffffff"><s:select list="{'博士','碩士','研究生','本科','專(zhuān)科','高中'}" name="education" id="education" headerKey="" headerValue="--選擇學(xué)歷--"></s:select></td><td height="22" align="center" bgColor="#f5fafe" class="ta_01">是否上傳簡(jiǎn)歷</td><td class="ta_01" bgColor="#ffffff"><s:select list="#{'1':'有','2':'無(wú)' }" name="isUpload" id="isUpload" headerKey="" headerValue="--請(qǐng)選擇--"></s:select></td></tr><tr><td width="100" height="22" align="center" bgColor="#f5fafe"class="ta_01"></td><td class="ta_01" bgColor="#ffffff"><font face="宋體" color="red"> ?</font></td><td align="right" bgColor="#ffffff" class="ta_01"><br><br></td><td align="right" bgColor="#ffffff" class="ta_01"><button type="submit" id="search" name="search" value="查詢(xún)" class="button_view"> 查詢(xún) </button><input type="reset" name="reset" value="重置" class="button_view"/></td></tr></table></td></tr><tr><td class="ta_01" align="center" bgColor="#afd1f3"><strong>用 戶 列 表</strong></TD></tr><tr><td class="ta_01" align="right"><button type="button" id="add" name="add" value="添加" class="button_add" onclick="addUser()"> 添加 </button></td></tr><tr><td class="ta_01" align="center" bgColor="#f5fafe"><table cellspacing="0" cellpadding="1" rules="all"bordercolor="gray" border="1" id="DataGrid1"style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; WIDTH: 100%; WORD-BREAK: break-all; BORDER-BOTTOM: gray 1px solid; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #f5fafe; WORD-WRAP: break-word"><trstyle="FONT-WEIGHT: bold; FONT-SIZE: 12pt; HEIGHT: 25px; BACKGROUND-COLOR: #afd1f3"><td align="center" width="18%">登錄名</td><td align="center" width="17%">用戶姓名</td><td align="center" width="8%">性別</td><td align="center" width="23%">聯(lián)系電話</td><td width="11%" align="center">學(xué)歷</td><td width="7%" align="center">編輯</td><td width="7%" align="center">查看</td><td width="7%" align="center">刪除</td></tr><s:iterator value="users" var="user"><tr onmouseover="this.style.backgroundColor = 'white'"onmouseout="this.style.backgroundColor = '#F5FAFE';"><td style="CURSOR: hand; HEIGHT: 22px" align="center"width="18%"><!-- user會(huì)push到root 同時(shí) 保存contextMap --><s:property value="logonName"/><s:property value="#user.logonName"/></td><td style="CURSOR: hand; HEIGHT: 22px" align="center"width="17%"><s:property value="#user.userName"/></td><td style="CURSOR: hand; HEIGHT: 22px" align="center"width="8%"><s:property value="#user.sex"/></td><td style="CURSOR: hand; HEIGHT: 22px" align="center"width="23%"><s:property value="#user.telephone"/></td><td style="CURSOR: hand; HEIGHT: 22px" align="center"><s:property value="#user.education"/></td><td align="center" style="HEIGHT: 22px"><s:a action="user_editview" namespace="/"><s:param name="userID" value="#user.userID"></s:param><img src="${pageContext.request.contextPath}/images/i_edit.gif" border="0" style="CURSOR: hand"></s:a></td><td align="center" style="HEIGHT: 22px"><s:a action="user_view" namespace="/"><s:param name="userID" value="#user.userID"></s:param><img src="${pageContext.request.contextPath}/images/button_view.gif" border="0" style="CURSOR: hand"></s:a></td><td align="center" style="HEIGHT: 22px"><s:a action="user_delete" namespace="/" cssClass="delLink"><s:param name="userID" value="#user.userID"></s:param><img src="${pageContext.request.contextPath}/images/i_del.gif" width="16" height="16" border="0" style="CURSOR: hand"></s:a></td></tr></s:iterator> </table></td></tr></TBODY></table></s:form></body> </HTML>
??
二.添加校驗(yàn)
三.完成條件查詢(xún)操作?? ?
?? ??? 1、是否上傳簡(jiǎn)歷,怎樣在action中獲取?
?? ??? ?
?? ??? ???? 需要在User中添加一個(gè)屬性? String isUpload
?? ??? ?
?? ???? 2、 在dao中怎樣根據(jù)條件查詢(xún)?
???????????? 在這里dao層我們使用的是dbutils,所以進(jìn)行條件查詢(xún)的時(shí)候需要用到QueryRunner類(lèi),而他的查詢(xún)方法queryRunner.query(sql,
?? ??? ??? ??? ??? ?new BeanListHandler<User>(User.class), argList.toArray());需要sql語(yǔ)句,和所有參數(shù)的這兩個(gè)參數(shù),所以我們需要解決這兩個(gè)問(wèn)題。
?? ??? ??? ?1).sql語(yǔ)句生成
?? ??? ??? ?
?? ??? ??? ?2).參數(shù)怎樣傳遞?
?? ??? ??? ??? ?創(chuàng)建一個(gè)List<Object>,在每一次判斷時(shí),直接將參數(shù)添加到集合中,
?? ??? ??? ??? ?最后將集合轉(zhuǎn)換成Object[],做為參數(shù)傳遞到query方法中。
?? ??? ??? ??? ?
?? ??? ??? ??
總結(jié)
以上是生活随笔為你收集整理的struts实战--实现条件查询(利用dbutils)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: struts实战--添加功能(重点文件上
- 下一篇: struts实战--文件下载