开发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!
。