2013-05-08 85 views
0

当生成通过Liferay的服务构建您的service.xml的实体,这是司空见惯的创建取景列类似下面的代码片段:Liferay的服务构建:创建发现者那场比赛至少有一列

<entity name="Person" local-service="true" > 
     <column name="personId" type="long" primary="true" /> 
     <column name="firstName" type="String" /> 
     <column name="lastName" type="String" /> 
     <finder name="AnyName" return-type="Collection" > 
      <finder-column name="firstName" /> 
      <finder-column name="lastName" /> 
     </finder> 
    <entity> 

这创建一个查找方法,可以找到与名字姓氏相匹配的实体。

如何创建与任意列匹配的查找程序。我需要生成类似于以下内容的SQL:从firstName =“firstname” lastName =“lastname”的人员进行SELECT。

这可能吗?

+0

直接通过finder方法,它似乎不可能。你可以在这里使用DynamicQuery。 – 2013-05-09 06:56:16

回答

0

您可能想使用DynamicQuery来使用'OR'语句。然后另一种方式,我能想到的是

加入这service.xml的

<finder name="FirstName" return-type="Collection" > 
     <finder-column name="firstName" /> 
    </finder> 

    <finder name="LastName" return-type="Collection" > 
     <finder-column name="lastName" /> 
    </finder> 

这对你PersonLocalServiceImpl

public List <Person> getPersonByAnyName(String firstName, String lastName) { 
     if (firstName != null && (lastName == null || lastName.equals(""))) { 
      return getPersonByFirstName(firstName); 
     } 
     if (lastName != null && (firstName == null || firstName.equals(""))) { 
      return getPersonByLastName(lastName); 
     } 

     return personPeristence.findByAnyName(firstName, lastName); 

    } 


    public List <Person> getPersonByFirstName(String firstName) { 
     // return the Collection from personPersistence.findByFirstName ... 
    } 

    public List <Person> getPersonByLastName(String lastName) { 
     // return the Collection from personPersistence.findByLastName ... 
    } 

编辑:哎呀,这个代码将不能作为OR语句工作,我工作,如果你的意思是使用其中一个Sting参数为空

+0

我认为DynamicQuery涵盖了它 – Olaseni 2013-05-13 07:19:19

相关问题