首页 > 代码库 > Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)
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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。