小编Hem*_*nth的帖子

如何在 Spring Rest api 响应中发送不带双引号的字符串

我有两个项目,projectA(spring boot),projectB(spring)

在这两个项目中,我有类似的返回字符串的 API。但是来自projectB API的响应有双引号,而projectA的响应中没有双引号

ProjectA [这是 Spring Boot 项目]

@PostMapping(path = "/tenants/{tenantId}/script/getNormalString")
    public String getNormalString(@PathVariable("tenantId") String tenantId,HttpServletRequest httpRequest) {
        try {
            String uuid = "normalString";
            return uuid;
        }  catch(Exception e) {
            logger.error("Error in getNormalString-> {}",e.getMessage(),e);
            throw new RestApiException(FAILED_GET,e.getMessage(),e);
        } 
    }
Run Code Online (Sandbox Code Playgroud)

回复

normalString
Run Code Online (Sandbox Code Playgroud)

项目B

@PostMapping(path = "/tenants/{tenantId}/script/getNormalString")
    public String getNormalString(@PathVariable("tenantId") String tenantId,HttpServletRequest httpRequest) {
        try {
            String uuid = "normalString";
            return uuid;
        }  catch(Exception e) {
            logger.error("Error in getNormalString-> {}",e.getMessage(),e);
            throw new RestApiException(FAILED_GET,e.getMessage(),e);
        } 
    }
Run Code Online (Sandbox Code Playgroud)

回复

"normalString"
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决为什么反应有差异吗?有没有办法发送不带双引号的响应?我尝试使用@Produces("text/plain")但响应仍然没有变化

java rest spring spring-boot spring-rest

6
推荐指数
0
解决办法
1186
查看次数

标签 统计

java ×1

rest ×1

spring ×1

spring-boot ×1

spring-rest ×1