Our Work
200+ Enterprises across globally trust KTree for their Web & Mobile application Development needs.See What We Do
Updated today
Liferay creates finders from service builder, in this Article we are discussing how to create custom finders in liferay 6.2/7.
This article also focuses on the below topics.
public class StudentLocalServiceImpl extends StudentLocalServiceBaseImpl {
public java.util.List<com.ktree.dbservice.model.Student>
findByGenderAndAge(int studentGender, int studentAge)
throws com.liferay.portal.kernel.exception.SystemException {
return StudentUtil.findByGender_Age(studentGender, studentAge);
}
<entity name="Student" local-service="true" remote-service="true" cache-enabled="false">
<entity name="Student" local-service="true" remote-service="true" cache-enabled="false">
http://gitlab.ktree.org/root/Proj_LiferayTraining6.2/tree/Dev_Raju/portlets/liferay_custom_service_methods-portlet/docroot/WEB-INF/src/com/ktree/dbservice/service/impl
Public List<Student> findByStudentAddress(String address){
DynamicQuery studentQuery = DynamicQueryFactoryUtil.forClass(
Student.class, PortletClassLoaderUtil.getClassLoader());
studentQuery.add(PropertyFactoryUtil.forName("studentAddress ").eq(new Integer ("Hyderabad")));
List<User> studentList=
StudentLocalServiceUtil.dynamicQuery(studentQuery);
Return studentList;
}
Following is the service.xml file to generate services for the Student table
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<service-builder package-path="com.ktree.dbservice">
<author>LiferayKTree</author>
<namespace>LK</namespace>
<entity name="Student" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="studentId" type="long" primary="true" />
<column name="firstName" type="String" />
<column name="lastName" type="String" />
<column name="studentAge" type="int" />
<column name="studentGender" type="int" />
<column name="studentAddress" type="String" />
<!-- Order -->
<order by="asc">
<order-column name="studentId" />
</order>
<!-- Finder methods -->
<finder name="Gender" return-type="Collection">
<finder-column name="studentGender"/>
</finder>
<!-- Finder methods -->
<finder name="Gender_Age" return-type="Collection">
<finder-column name="studentGender"/>
<finder-column name="studentAge"/>
</finder>
</entity>
</service-builder>
KTree is the best offshore Liferay development company with extensive experience in Liferay Portal Development services along with Upgrade & Migration. Hire Liferay developers or Liferay development services from LiferayDeveloper.