「Spring」@RequestMappingのproducesでxmlタイプを指定する

2021年9月3日

書式
@RequestMapping(value = パス名, produces = “application/xml")
@RequestMapping(value = パス名, produces = MediaType.APPLICATION_XML_VALUE)

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@RequestMapping(value = "/getFile", produces = "application/xml")
public String getFile() {
return "<note><to>changfa</to></note>";
}
@RequestMapping(value = "/getFile", produces = "application/xml") public String getFile() { return "<note><to>changfa</to></note>"; }
@RequestMapping(value = "/getFile", produces = "application/xml")
public String getFile() {
    return "<note><to>changfa</to></note>";
}

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@RequestMapping(value = "/getFile", produces = MediaType.APPLICATION_XML_VALUE)
public String getFile() {
return "<note><to>changfa</to></note>";
}
@RequestMapping(value = "/getFile", produces = MediaType.APPLICATION_XML_VALUE) public String getFile() { return "<note><to>changfa</to></note>"; }
@RequestMapping(value = "/getFile", produces = MediaType.APPLICATION_XML_VALUE)
public String getFile() {
    return "<note><to>changfa</to></note>";
}

 

Spring Boot

Posted by arkgame