按条件搜索说明

                                                                           按条件搜索说明

 

文章搜索页面如图所示:

 

helpContentList组件中的部分代码如下:

 

@Name("helpContentList")

public class HelpContentList extends EntityQuery<HelpContent> {

    private static final String EJBQL = "select helpContent from HelpContent helpContent";

 

    private static final String[] RESTRICTIONS = {

           "lower(helpContent.title) like lower(concat(#{helpContentList.helpContent.title},'%'))",

           "helpContent.helpCat.id=#{helpContentList.helpContent.helpCat.id}", };

    private HelpContent helpContent = new HelpContent();// 主要用来做查询,构造el表达式

 

    public HelpContentList() {

       setEjbql(EJBQL);

       setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));

       setMaxResults(10);

       setOrder("show_order desc and id desc");

    }

 

 

文章列表的部分代码如下:

<rich:dataTable   var="_helpContent" value="#{helpContentList.resultList}">

              <h:column>

                  <f:facet name="header">标题</f:facet>

                    #{_helpContent.title}

                </h:column>

           </rich:dataTable>

 

·   resultList列表的获取有几个参数,如:EjbqlRestrictionExpressionStringsMaxResultsOrder  在构造函数中通过设置

setEjbql(EJBQL);

    setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));

    setMaxResults(10);

    setOrder("show_order desc and id desc");

来获取列表

 

·   EJBQL是固定的

·   RESTRICTIONS是条件。

#{helpContentList.helpContent.title}#{helpContentList.helpContent.helpCat.id}为空的时候,RESTRICTIONS条件不起作用。当它们不为空时,RESTRICTIONS起作用。

·   MaxResults设置列表的分页单位,即一个页面最多显示的文章条数

·   Order设置文章的根据什么条件来排序

 

 

 

当第一次打开页面的时候 #{helpContentList.helpContent.title}#{helpContentList.helpContent.helpCat.id}都为空,所以显示出来的是所有的文章,分页单位是10,按照idshow_order倒序排序

 

 

 

搜索部分的代码如下:

 

<h:inputText value="#{helpContentList.helpContent.title}" />

<h:selectOneMenu value="#{helpContentList.helpContent.helpCat}">

  <s:selectItems value="#{helpCatList.helpLeafCats}" var="_helpCats"

           label="#{_helpCats.wrapName.replace(' ','&#160;')}"

           rendered="#{not empty helpCatList.helpLeafCats}"

                         noSelectionLabel="==请选择==" />

    <s:convertEntity></s:convertEntity>

</h:selectOneMenu>

 

 

这部分代码中文本框组件绑定了#{helpContentList.helpContent.title},选择框组件绑定了#{helpContentList.helpContent.helpCat},当它们有值的时候,后台的setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));

成立。没有值的时候不成立,从而达到根据条件搜索的功能。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值