基于liferay7开发Rest接口

2017-12-18  本文已影响0人  降龙十八段

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

image.png

结构如下:


image.png

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

image.png

2、添加server,点击add;


image.png

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


image.png

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

image.png image.png

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

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


image.png

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


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

    public Set<Object> getSingletons() {
        return Collections.<Object>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 包;


image.png

5、浏览器访问

image.png image.png image.png image.png
上一篇 下一篇

猜你喜欢

热点阅读