在Liferay Service Builder中删除有关特定字段值的记录 [英] Delete record on sepecific field value in liferay service builder
问题描述
我想使用字段名称删除特定记录
I want to delete specific record using Field Name
表:虚拟实体
- 字段ID
-
字段名称
- Field Id
Field Name
public void deleteLocation(req, res){
String getLocationName = request.getParameter("locationName");
Location locationToDelete = new LocationImpl();
locationToDelete.setLocationName(getLocationName);
LocationLocalServiceUtil.deleteLocation(locationToDelete);
}
它没有显示任何错误,但记录没有被删除.请帮我出来.
It's not showing me any error but the record doesn't get deleted. Please hep me out.
推荐答案
最简单的方法是为service.xml
中的特定字段添加<finder>
节点,如下所示(假设Location
是您的实体名称) ,name
是您的字段名称,Name
是service.xml
中的查找器条目的名称)和构建服务:
The simplest way to achieve this is to add <finder>
node for that specific field in service.xml
, as following (saying Location
is your entity name, name
is your field name and Name
is the name of finder entry in service.xml
) and build service:
<column name="name" type="String" />
<finder name="Name" return-type="Collection">
<finder-column name="name" />
</finder>
成功构建后,它将基于该列在您的服务中创建CRUD操作.现在,您可以在LocationUtil.java
中找到以下方法:
On successful build, it will create CRUD operations in your service based on that column. Now you can find following methods in your LocationUtil.java
:
findByName,
removeByName,
countByName,
在LocationLocalServiceImpl.java
中创建以下(新)方法:
Create following (new) method in LocationLocalServiceImpl.java
:
public void deleteLocationsByName(String name){
try{
LocationUtil.removeByName(name);
}catch(Exception ex){
// log your exception
}
}
同样,在构建服务时,该方法将在LocationLocalServiceUtil.java
中的操作类中使用,您可以在其中将其称为:
Again, on building service, this method will be available for use in your action class from LocationLocalServiceUtil.java
, where you can call it like:
public void deleteLocation(req, res){
String locationName = request.getParameter("locationName");
LocationLocalServiceUtil.deleteLocationsByName(locationName);
}
就是这样,您已经在服务中添加了自定义查找器方法.
That's it, you have added custom finder method to your service.
这篇关于在Liferay Service Builder中删除有关特定字段值的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!