使用REST端点返回字符串

 guoqiuping98_376 发布于 2023-01-07 15:57

在你减去这个问题之前,你应该知道我搜索了解决方案而没有找到它.

我想通过rest端点返回String:

    @GET
    @Path("/getMyString")
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getId() {
    String s = "this is my string";
    (...)
    return Response.ok(s).build();
    }

但是在视图中我收到了char数组(结果是firebug):

Resource { 0="t", 1="h", 2="i", more...}

在前面我使用角度资源,如:

blablaResources.factory('AngularApp', [ '$resource', function($resource) {
    return $resource(contextPath + '/.rest/v1/someService', {}, {
        (... other methods ...)
        getString : {
            method : 'GET',
            url : contextPath + '/.rest/v1/someService/getMyString'
        }
    });
} ]);

是否有任何String或注释的包装类来发送它:

Resource { value = "this is my string" }

或者只是正常

"this is my string"

感谢任何建设性的回应:)

1 个回答
  • 尝试使用

    @Produces({ MediaType.TEXT_PLAIN })
    

    2023-01-07 15:58 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有