开发API操作

在spring boot中通过spring mvc的controller来实现api操作。

jmms自动检测spring boot是否存在相同HTTP Method和Path的路由,优先使用spring boot的实现。

下面以hello操作为例进行说明:

  • 创建app/operations/hello.js:

hello.js

/**
 * @returns {string}
 */
function hello() {
    return "not implemented";
}

路由记录为:

GET     /hello          ~/operations/hello.js

此时访问http://localhost:8080/hello返回的是"not implemented"

  • 创建HelloController.java
@RestController
public class HelloController {
    @GetMapping(path = "/hello")
    public String hello() {
        return "Hello world!";
    }
}

路由记录变更为:

GET     /hello          spring:HelloController.hello()

再次访问http://localhost:8080/hello返回的是Hello world!

Bingosoft            updated 2018-07-23
上一篇:初始化工程 下一篇:实体定义

results matching ""

    No results matching ""