隨筆-39  評論-33  文章-0  trackbacks-0

          利用newxy(新坐標(biāo))技術(shù)可以不寫一行java代碼實(shí)現(xiàn)多項(xiàng)查詢。(在線演示http://www.newxy.net/zh_cn/samples/sample4/demo.jsp)

          • newxy( 新坐標(biāo))多項(xiàng)查詢利用了NQL查詢類。
          • newxy( 新坐標(biāo))多項(xiàng)查詢用到三個標(biāo)簽,<nlogic:action1><nlogic:action2><nhtml:form /><nhtml:button />
          • <nhtml:form />標(biāo)簽內(nèi)不要用 submit之類的標(biāo)簽,如<html:submit value=""></html:submit><input type="submit" value=""/>, 取而代之的是<nhtml:button actionId="" method="find" />
          • <nhtml:button actionId="" method="find" /> 不一定要放到<nhtml:form />標(biāo)簽內(nèi)。

          范例對行業(yè)表、企業(yè)表聯(lián)表查詢,查詢的最基本條件是 企業(yè)表的行業(yè)代碼字段值等于行業(yè)表某條主關(guān)鍵字段值。就是:
          ????enterprise.industry_code=industry.code
          用戶所選擇查詢條件與基本條件是 and 關(guān)系。根據(jù)這樣的前提構(gòu)成的最基本查詢語句:
          ????select a.industry,b.* from industry a,enterprise b where{a.code=b.industry_code}
          newxy(
          新坐標(biāo))將為此創(chuàng)建NQL實(shí)例:nql=new NQL(dao,"select a.industry,b.* from industry a,enterprise b where{a.code=b.industry_code}");
          注意:where后緊跟的是大括號{}
          為了讓理解方便,范例中實(shí)際是行業(yè)大類述為行業(yè)代碼

          <nlogic:action1/> 標(biāo)簽應(yīng)放在<nhtml:form />標(biāo)簽上面,這兩個標(biāo)簽針同一個formBean,因此屬性formName值相同,在此formName="enterprise"

          <nlogic:action1 id="act1" formName="enterprise"/>

          <nhtml:form action=""? formName="enterprise">

          ? <html:hidden property="_dao" value="dao.default"/>

          ? <nhtml:hidden property="_sql"

          ????? value=" select a.industry,b.* from industry as a,enterprise as b where{a.code=b.industry_code} "/>

          ? <table border="1">

          ??? <tr>

          ????? <td> 邏輯</td>

          ????? <td>

          ??????? <html:radio property="lg" value="1"> 并且</html:radio>

          ??????? <html:radio property="lg" value="0"> 或者</html:radio>

          ????? </td>

          ??? </tr>

          ??? <tr>

          ????? <td> 行業(yè)</td>

          ????? <td> 等于</td>

          ????? <td>

          ??????? <nhtml:hidden property="_item1" value="a.code"/>

          ??????? <html:hidden property="_item1" value="="/>

          ??????? <html:select property="_item1">

          ????????? <html:option value=""></html:option>

          ????????? <html:option value="A"> 農(nóng)、林、牧、漁業(yè)</html:option>

          ????????? <html:option value="B"> 采礦業(yè)</html:option>

          ????????? <html:option value="C"> 制造業(yè)</html:option>

          ??????? </html:select> 作為范例,行業(yè)沒全列出。

          ????? </td>

          ??? </tr>

          ??? <tr>

          ????? <td> 企業(yè)名稱</td>

          ????? <html:hidden property="_item2" value="b.name"/>

          ????? <td>

          ??????? <html:select property="_item2">

          ????????? <html:option value=""></html:option>

          ????????? <html:option value="="> 等于</html:option>

          ????????? <html:option value="like"> 包含</html:option>

          ??????? </html:select>

          ????? </td>

          ?? ???<td>

          ??????? <html:text property="_item2">

          ??????? </html:text>

          ????? </td>

          ??? </tr>

          ? </table>

          </nhtml:form>

          加入標(biāo)簽<nhtml:button actionId="act1" method="find" value="查 詢"/>,產(chǎn)生查詢銨鈕

          產(chǎn)生的查詢介面如下:


          如果想知道行成的sql語句,可以用struts標(biāo)簽:<bean:write name="enterprise" property="_sql"/>

          說明:

          • <nhtml:form />action 屬性值為空,是以當(dāng)前路徑為值。可查看產(chǎn)生的靜態(tài)頁面。
          • <html:hidden property="_dao" value="dao.default"/>
            其作用是指明由哪個DAO類來處理。默認(rèn)值是dao.default,此處可以不用,只為演示。"_dao"是特定的屬性名
          • <nhtml:hidden property="_sql" value="select a.industry,b.* from industry as a,enterprise as b where{a.code=b.industry_code}"/>
            在此不用struts<html:hidden/>標(biāo)簽或<input type="hidden" name="_sql" value="......"/>,是因?yàn)橐陟o態(tài)頁面上不顯示這條sql語名,達(dá)到安全的目的。 范例靜態(tài)頁面上產(chǎn)生的是<input type="hidden" name="_sql" value="_hidden_sql_1">。 其它幾處<nhtml:hidden />作用相同。
          • 而且、或者邏輯關(guān)系由 <html:radio property="_lg" value="1">并且</html:radio> <html:radio property="_lg" value="0">或者</html:radio>決定。
            _lg
            是特定的屬性名
          • 其它查詢項(xiàng)的組合方法與企業(yè)名稱行業(yè)代碼查詢項(xiàng)的組合方式相同。
            按照例中的組合,_item1的值可行成類似a.code='A'_item2的值可形成類似b.name like '%公司%'
            必須一組三項(xiàng),三項(xiàng)用同一屬性名,屬性名以"_item"開頭,后用不同數(shù)字區(qū)分。
          • 另有組合方式在后序技術(shù)文檔中補(bǔ)充,此文檔暫不介紹。

          利用<nlogic:iterate id="" name="" property=""></nlogic:iterate>標(biāo)簽、<nlogic:navigate/>標(biāo)簽、<nhtml:TR></nhtml:TR>標(biāo)簽、<nhtml:javascripts/>標(biāo)簽、<nhtml:stylesheets/>標(biāo)簽來分頁顯示查詢結(jié)果。
          建義<nhtml:javascripts/>標(biāo)簽、<nhtml:stylesheets/>標(biāo)簽兩標(biāo)簽放在頁首或較前部。如果有javascripts腳本錯本且數(shù)據(jù)列表沒有光帶, 是因?yàn)闆]有使用<nhtml:javascripts/>標(biāo)簽、<nhtml:stylesheets/>標(biāo)簽。

          <nhtml:javascripts/>

          <nhtml:stylesheets/>

          <logic:notEmpty name="enterprise" property="_coll">

          ? <table>

          ? <nlogic:iterate id="rec" name="enterprise" property="_coll">

          ??? <nhtml:TR>

          ????? <td>1</td>

          ????? <td><bean:write name="rec" property="industry"/></td>

          ????? <td><bean:write name="rec" property="name"/></td>

          ??? </nhtml:TR>

          ? </nlogic:iterate>

          ? </table>

          </logic:notEmpty>

          ?

          下圖是范例查詢結(jié)果

          ?

          ?

          范例的完整jsp代碼如下:



          <%@ page contentType="text/html; charset=GBK" %>
          <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
          <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
          <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

          <%@ taglib uri="/WEB-INF/newxy-html.tld" prefix="nhtml"%>
          <%@ taglib uri="/WEB-INF/newxy-logic.tld" prefix="nlogic"%>
          <%@ taglib uri="/WEB-INF/newxy-bean.tld" prefix="nbean"%>
          <nhtml:javascripts/>
          <nhtml:stylesheets/>

          <nlogic:action1 id="actResource" formName="resources"/>

          <nbean:formBean name="resources" sql="select resource_id,resName from resources"/>

          <logic:present name="resources">
          ? <logic:notEmpty name="resources" property="_coll">
          <div style="padding-left:40px">
          <table border="0" width="700">
          ? <tr>
          ??? <td valign="top">
          ????? <table border="0" width="300">
          ??????? <tr>
          ????????? <td style="font-size:14px"><b>資源下載</b></td>
          ??????? </tr>
          ??????? <nlogic:iterate id="rec" name="resources" property="_coll">
          ????????? <nhtml:TR onclick="edit(actResource);">
          ??????????? <td style="cursor:hand">
          ????????????? <bean:write name="rec" property="resName"/>
          ??????????? </td>
          ????????? </nhtml:TR>
          ??????? </nlogic:iterate>
          ????? </table>
          ??? </td>
          ??? <bean:define id="_id" name="resources" property="resource_id">
          ??? </bean:define>
          ??? <nbean:formBean cache="false" refresh="true" name="resource" sql="select * from resources where resource_id="/>
          ??? <td valign="top">
          ????? <table border="0" width="400">
          ??????? <tr>
          ????????? <td><b>資源名:</b></td><td>&nbsp;<bean:write name="resource" property="resName"/></td>
          ??????? </tr>
          ??????? <tr>
          ????????? <td><b>版本:</b></td><td>&nbsp;<bean:write name="resource" property="ver"/></td>
          ??????? </tr>
          ??????? <tr>
          ????????? <td><b>備注:</b></td><td>&nbsp;<p style="width:300px"><bean:write name="resource" property="remark"/></p></td>
          ??????? </tr>
          ??????? <tr>
          ????????? <td><b>上傳日期:</b></td><td>&nbsp;<bean:write name="resource" property="uploadDate" format="yyyy年MM月dd日"/></td>
          ??????? </tr>
          ??????? <tr>
          ????????? <td colspan="2">&nbsp;<html:link target="_blank" page="/download?name=resource&property=content&fileName=resName">下載</html:link></td>
          ??????? </tr>
          ????? </table>
          ??? </td>
          ? </tr>
          </table>
          </div>
          ? </logic:notEmpty>
          </logic:present>

          posted on 2007-03-08 00:18 newxy新坐標(biāo) 閱讀(1965) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 石河子市| 炎陵县| 尤溪县| 日喀则市| 石屏县| 扶沟县| 城步| 舞阳县| 临泽县| 宁波市| 钟祥市| 永平县| 静宁县| 永和县| 尤溪县| 东港市| 正镶白旗| 长岭县| 昌邑市| 巢湖市| 安达市| 阳城县| 西畴县| 浦城县| 任丘市| 财经| 黄石市| 萝北县| 岳池县| 永嘉县| 宁明县| 专栏| 灵璧县| 宣威市| 焉耆| 长武县| 大港区| 南靖县| 黄陵县| 高台县| 伊通|