随笔-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 />标签内。

范例对行业表、企业表联表查询,查询的最基本条件是 企业表的行业代码字段值等于行业表某条主关键字段值。就是:
    enterprise.industry_code=industry.code
用户所选择查询条件与基本条件是 and 关系。根据这样的前提构成的最基本查询语句:
    select a.industry,b.* from industry a,enterprise b where{a.code=b.industry_code}
newxy(
新坐标)将为此创建NQL实例:nql=new NQL(dao,"select a.industry,b.* from industry a,enterprise b where{a.code=b.industry_code}");
注意:where后紧跟的是大括号{}
为了让理解方便,范例中实际是行业大类述为行业代码

<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> 行业</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"> 农、林、牧、渔业</html:option>

          <html:option value="B"> 采矿业</html:option>

          <html:option value="C"> 制造业</html:option>

        </html:select> 作为范例,行业没全列出。

      </td>

    </tr>

    <tr>

      <td> 企业名称</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 属性值为空,是以当前路径为值。可查看产生的静态页面。
  • <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="......"/>,是因为要在静态页面上不显示这条sql语名,达到安全的目的。 范例静态页面上产生的是<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
    是特定的属性名
  • 其它查询项的组合方法与企业名称行业代码查询项的组合方式相同。
    按照例中的组合,_item1的值可行成类似a.code='A'_item2的值可形成类似b.name like '%公司%'
    必须一组三项,三项用同一属性名,属性名以"_item"开头,后用不同数字区分。
  • 另有组合方式在后序技术文档中补充,此文档暂不介绍。

利用<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新坐标 阅读(1960) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: