显示\ n而非新行

时间:2018-03-21 20:04:47

标签: spring rest text response

我正在尝试为Spring应用程序生成TEXT / PLAIN响应。

当我调试代码时,我看到格式很好的字符串:

LINE1
LINE2
...

但是当我在Postman中看到响应时,我发现输出都像

一样搞砸了
LINE1\nLIINE2\n....

我不确定是否正确设置控制器!

这是我的Controller类:

import java.io.StringReader;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Configuration
@EnableAutoConfiguration
public class ConfigGeneratorController {

    private final AtomicLong counter = new AtomicLong();

    Logger logger = null;

    @RequestMapping(value = "/configGenerator", method = {RequestMethod.POST})
    @Consumes({MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE})
    @Produces({MediaType.TEXT_PLAIN_VALUE})

    public ConfigGenerator configGenerator(@RequestBody String xml) {

        logger = Logger.getLogger(ConfigGeneratorController.class.getName());

        .
        .
        .
        bunch of code
        .
        .
        .

        return new ConfigGenerator(counter.incrementAndGet(), String.format(actionMonitor.getGeneratedConfig().replaceAll("^\t+", "")));
    }

}

actionMonitor.getGeneratedConfig()是返回字符串的方法。

0 个答案:

没有答案