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语法真是简洁。
关于作者:
王昕(QQ:475660)
在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
目前维护的开源产品:https://gitee.com/475660
目前维护的开源产品:https://gitee.com/475660