基于liferay7开发Rest接口

1、创建 Liferay Workspace project 命名demo(自定义),Build type默认Gradle。

基于liferay7开发Rest接口_第1张图片
image.png

结构如下:


基于liferay7开发Rest接口_第2张图片
image.png

gradle.properties文件中添加服务器配置 liferay.workspace.home.dir=D:/liferaydevelop/tomcat/liferay-ce-portal-7.0-ga3

基于liferay7开发Rest接口_第3张图片
image.png

2、添加server,点击add;


基于liferay7开发Rest接口_第4张图片
image.png

配置server,tomcat服务器路径,Jdk路径,start/debug;


基于liferay7开发Rest接口_第5张图片
image.png

3、在demo下的modules文件夹下,新建Liferay Module Project 命名rest,Project Template Name 选择“rest”

基于liferay7开发Rest接口_第6张图片
image.png
基于liferay7开发Rest接口_第7张图片
image.png

build.gradle文件中,添加项目所依赖的jar(本地/在线);

bnd.bnd文件中,自动生成的配置路径不可用,修改成下面的方式;


基于liferay7开发Rest接口_第8张图片
image.png

自动生成Rest1Application 文件,代码如下:


/**
 * @author photo
 */
@ApplicationPath("/greetings")
@Component(immediate = true, service = Application.class)
public class Rest1Application extends Application {

    public Set getSingletons() {
        return Collections.singleton(this);
    }

    @GET
    @Produces("text/plain")
    public String working() {
        return "It works!";
    }

    @GET
    @Path("/morning")
    @Produces("text/plain")
    public String hello() {
        return "Good morning!";
    }

    @GET
    @Path("/morning/{name}")
    @Produces("text/plain")
    public String morning(
        @PathParam("name") String name,
        @QueryParam("drink") String drink) {

        String greeting = "Good Morning " + name;

        if (drink != null) {
            greeting += ". Would you like some " + drink + "?";
        }

        return greeting;
    }

}

4、使用“clean”,“deploy” 刷新生成jar 包;


基于liferay7开发Rest接口_第9张图片
image.png

5、浏览器访问

基于liferay7开发Rest接口_第10张图片
image.png
基于liferay7开发Rest接口_第11张图片
image.png
基于liferay7开发Rest接口_第12张图片
image.png
基于liferay7开发Rest接口_第13张图片
image.png

你可能感兴趣的:(基于liferay7开发Rest接口)