文档详情

《Liferay-EXT通过SQL语句数据库查询》.docx

发布:2015-10-18约5.93千字共6页下载文档
文本预览下载声明
Liferay的EXT框架封装的Hibernate 数据持久层下实现通过SQL语句数据库查询 以com.gsoft.portlet.task包下实体Task_Info(对应生成都持久层的service.xml文件中的entity name=Task_Info)为例的步骤: 将liferay的源代码下(如5.2.3版本的源代码liferay-portal-src-5.2.3)portal-impl\src下的整个custom-sql目录拷到Liferay的EXT框架的源代码下(如5.2.3版本的源代码liferay-portal-ext-5.2.3)ext-impl\src下,如果不整个custom-sql目录拷过去,会后台会报如下图错误: 模仿custom-sql目录的XML文件编写一个存放SQL语句的XML文件,并将所编写XML文件的路径加到default.xml文件中。 如编写一个task.xml文件: ?xml version=1.0? custom-sql sql id=com.gsoft.portlet.task.service.persistence.Task_InfoFinder.queryTask ![CDATA[ SELECT {TASK_INFO.*} FROM TASK_INFO WHERE (VARAPPID = ?) AND (VARAPPTASKID = ?) ]] /sql /custom-sql 对表TASK_INFO查询,文件中TASK_INFO是表名,可以根据自己需要和格式在文件中加多个SQL语句。 所编写task.xml文件的路径加到default.xml文件中(红字部分): ?xml version=1.0? custom-sql sql file=custom-sql/portal.xml / sql file=custom-sql/announcements.xml / sql file=custom-sql/blogs.xml / sql file=custom-sql/bookmarks.xml / sql file=custom-sql/calendar.xml / sql file=custom-sql/documentlibrary.xml / sql file=custom-sql/expando.xml / sql file=custom-sql/imagegallery.xml / sql file=custom-sql/journal.xml / sql file=custom-sql/messageboards.xml / sql file=custom-sql/permission.xml / sql file=custom-sql/polls.xml / sql file=custom-sql/shopping.xml / sql file=custom-sql/social.xml / sql file=custom-sql/tags.xml / sql file=custom-sql/tasks.xml / sql file=custom-sql/wiki.xml / sql file=custom-sql/task.xml / /custom-sql 2、在ext-impl\src下的com.gsoft.portlet.task.service.persistence包下新建一个Task_InfoFinderImpl.java,该类同Task_InfoPersistenceImp.java类一样集成BasePersistenceImpl.java类,并实现Task_InfoFinder接口。SQL语句也可以不写到custom-sql目录的XML文件中,而直接在该类中拼写。 如Task_InfoFinderImpl.java类中queryTask 方法是将SQL语句写到custom-sql目录的XML文件中,而queryTaskInfo方法是将SQL语句直接在该类中拼写,代码如下: package com.gsoft.portlet.task.service.persistence; import com.gsoft.portlet.task.model.Task_Info; import com.gsoft.portlet.task.model.impl.Task_AppsImpl; import com.gsoft.portlet.task.model.impl.Task_InfoImpl; import com.liferay.portal.Syste
显示全部
相似文档