Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)
Posted 昕友软件开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)相关的知识,希望对你有一定的参考价值。
在liferay7中开发不依赖Service Builder的对外服务类,非常简洁,只需要2点注解:
- 在类的前部定义:
@ApplicationPath("/PathXXX")
- 方法前定义:
@GET
@Path("/ActionXXX")
@Produces("text/plain")
例子:得到注册用户
import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.service.UserLocalService; import java.util.Collections; import java.util.Set; import javax.ws.rs.ApplicationPath; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Application; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @ApplicationPath("/allUsers") @Component( immediate = true, property = {"jaxrs.application=true"}, service = Application.class ) public class UsersRestService extends Application { @Override public Set<Object> getSingletons() { return Collections.singleton((Object)this); } @GET @Path("/list") @Produces("text/plain") public String getAllUsers() { StringBuilder result = new StringBuilder(); for (User user : _userLocalService.getUsers(-1, -1)) { result.append(user.getFullName()).append(",\n"); } return result.toString(); } @Reference public void setUserLocalService(UserLocalService userLocalService) { _userLocalService = userLocalService; } private UserLocalService _userLocalService; }
osgi语法真是简洁。
以上是关于Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)的主要内容,如果未能解决你的问题,请参考以下文章
Liferay7 BPM门户开发之17: Portlet 生命周期
Liferay7 BPM门户开发之3: Activiti开发环境搭建
Liferay7 BPM门户开发之14: Liferay开发体系简介
Liferay7 BPM门户开发之30: 通用帮助类ValidatorArrayUtilStringUtil等使用