• 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(",
    ");
            }
            return result.toString();
        }
    
        @Reference
        public void setUserLocalService(UserLocalService userLocalService) {
            _userLocalService = userLocalService;
        }
    
        private UserLocalService _userLocalService;
    
    }
    osgi语法真是简洁。
  • 相关阅读:
    output中的path和publicPath
    CSS3 animation设置图片上下移动
    富文本编辑器UEditor
    日历插件:Bootstrap的datetimepicker插件
    文档流、浮动 、定位的概念【转】
    css position [转]
    css line-height [转]
    div 中 id 和 class使用详解【转】
    js中的require、define、export、import【转】
    js 立即调用函数 IIFE(Immediately Invoked Function Expression) 【转】
  • 原文地址:https://www.cnblogs.com/starcrm/p/6061423.html
Copyright © 2020-2023  润新知