Spring-boot return json and xml from controllers

前端 未结 8 1488
Happy的楠姐
Happy的楠姐 2020-12-16 12:05

I have a spring-boot 1.1.7 application that uses Thymeleaf for much of the UI, so the response from my controllers hasn\'t really been a concern. However, now I need to pro

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 12:32

    In my case I wanted to return a formatted xml string and it was all combined into one line.

    Adding produces = { "application/xml", "text/xml" } to the request mapping was enough to return the string as formatted XML (with indentation).

    example:

    @RequestMapping(method= RequestMethod.GET, value="/generate/{blabla}", produces = { "application/xml", "text/xml" })
    public String getBlaBla(@PathVariable("param") String param) throws IOException {
    

    }

    Goodluck.

提交回复
热议问题