0

试图查看我是否可以公开 curl http://localhost:9090/studentinfo?schoolId=12341324,其中“studentinfo”是服务路径。

    @http:ServiceConfig { basePath: "/studentinfo" }
    service<http:Service> studentInfo bind studentInfoListener {

            @http:ResourceConfig {
                methods: ["GET"],
                path: "?"
            }
            getStudentBySearch(endpoint client, http:Request req) {

                http:Response response;

                var params = req.getQueryParams();
                var schoolId = <string>params.schoolId;
                var addmissionYear = <string>params.addmissionYear;
            ...
            }
    ...
    }
4

2 回答 2

2

在 ballerina 中,请求是基于路径和 HTTP 动词分派的。当涉及到默认资源时,路径和动词都不应限制请求。请考虑以下代码片段。

@http:ResourceConfig {
    path: "/*"
}
getStudentBySearch(endpoint client, http:Request req) {

    http:Response response;

    var params = req.getQueryParams();
    var schoolId = <string>params.schoolId;
    var addmissionYear = <string>params.addmissionYear;
...
}

这里没有特别说明 HTTP 动词。这意味着任何动词都是允许的。

当 path 定义为“/*”时,basePath 之后的任何路径段都将在没有特定匹配的情况下与之匹配。

示例网址:

http://localhost:9090/studentinfo?schoolId=12341324 ,

http://localhost:9090/studentinfo/resourcePath?schoolId=12341324

http://localhost:9090/studentinfo/name -X POST

于 2018-05-23T02:28:08.307 回答
1

仅使用“/”作为资源路径应该可以工作。

@http:ResourceConfig {
    methods: ["GET"],
    path: "/"
}
于 2018-05-22T17:12:29.410 回答