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

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

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

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

          <nlogic:action1/> 標簽應放在<nhtml:form />標簽上面,這兩個標簽針同一個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"> 農、林、牧、漁業(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>

          加入標簽<nhtml:button actionId="act1" method="find" value="查 詢"/>,產生查詢銨鈕

          產生的查詢介面如下:


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

          說明:

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

          利用<nlogic:iterate id="" name="" property=""></nlogic:iterate>標簽、<nlogic:navigate/>標簽、<nhtml:TR></nhtml:TR>標簽、<nhtml:javascripts/>標簽、<nhtml:stylesheets/>標簽來分頁顯示查詢結果。
          建義<nhtml:javascripts/>標簽、<nhtml:stylesheets/>標簽兩標簽放在頁首或較前部。如果有javascripts腳本錯本且數據列表沒有光帶, 是因為沒有使用<nhtml:javascripts/>標簽、<nhtml:stylesheets/>標簽。

          <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>

          ?

          下圖是范例查詢結果

          ?

          ?

          范例的完整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新坐標 閱讀(1965) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 石首市| 金湖县| 内乡县| 南丰县| 衡水市| 沙洋县| 海门市| 梁山县| 昭觉县| 深州市| 镇赉县| 龙岩市| 呈贡县| 龙陵县| 江陵县| 株洲县| 绥化市| 大同县| 石河子市| 玛曲县| 大邑县| 娄底市| 清水河县| 渭源县| 海阳市| 天峻县| 廉江市| 乐安县| 贡嘎县| 沙河市| 滨州市| 读书| 勃利县| 资源县| 子长县| 陇川县| 拜城县| 高雄县| 闻喜县| 武川县| 铁岭市|