欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Liferay 之 二 增删改查

程序员文章站 2022-07-15 13:39:05
...

1. Liferay 连接MySQL数据库, 创建配置文件

  1.1 文件名: portal-ext.properties

  1.2 文件路径: Liferay bundle 根目录

  1.3 内容

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=123456

 

2. 使用Service Builder生成数据基本操作的代码

  2.1 右键项目,选择创建Liferay Service Builder. 生成的service.xml默认路径是docroot/WEB-INF

Liferay 之 二 增删改查

Liferay 之 二 增删改查

  2.2 service.xml 内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.project.gen">
	<author>juhu</author>
	<namespace>PR</namespace>

	<entity name="PRProduct" local-service="true" remote-service="false">
		<column name="productId" type="long" primary="true" />
		<column name="productName" type="String" />
		<column name="serialNumber" type="String" />
		<column name="companyId" type="long" />
		<column name="groupId" type="long" />

		<order by="asc">
			<order-column name="productName"></order-column>
		</order>

		<finder return-type="Collection" name="G_PN">
			<finder-column name="groupId" />
			<finder-column name="productName" />
		</finder>
		<finder return-type="Collection" name="GroupId">
			<finder-column name="groupId" />
		</finder>
		<finder return-type="Collection" name="CompanyId">
			<finder-column name="companyId" />
		</finder>
	</entity>
</service-builder>

   2.3 运行service.xml文件。 右键Liferay/build service

   2.4 A lot of code will be generated including model code, service code, table sql etc. For the generated code, what we should focus on is com/project/gen/service/impl/xxxLocalServiceImpl.java file and add the logic method here.

public class xxxLocalServiceImpl extends xxxLocalServiceBaseImpl {
}
 

3. Create portlets.

  3.1 Right click project to create a new portlet.

  3.2

相关标签: Liferay