java - 使用 REST 端点返回字符串

标签 java angularjs rest

在你忽略这个问题之前,你应该知道我搜索了解决方案但没有找到。

我想通过 rest 端点返回字符串:

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

但是在 View 中我收到了 char 数组(导致 Firebug ):

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

在前面我使用像这样的 Angular 资源:

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"

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

最佳答案

尝试使用

@Produces({ MediaType.TEXT_PLAIN })

关于java - 使用 REST 端点返回字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24424305/

相关文章:

java - 如何在现有的Web 项目中集成Web 服务?

jquery - AngularJS 是否有等效的 jQuery.ajaxSuccess

javascript - 项目未添加到集合中

angularjs - 如何对 $timeout 调用进行单元测试/模拟?

rest - 基本 HTTP 和不记名 token 身份验证

.net - HTTP 方法 GET、POST、PUT 和 DELETE 之间有什么区别

javascript - 将查询参数与集合运算符一起使用

java - Grizzly 项目是否处理缓冲区溢出或拒绝服务攻击?

java urlconnection 获取最终重定向的 URL

java - 如何在mongoquery中展开两个数组