依赖:
<dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </dependency>
定义对象与Xml的关系:
@Data @JacksonXmlRootElement(localName = "User") public class User { @JacksonXmlProperty(localName = "name") private String name; @JacksonXmlProperty(localName = "age") private Integer age; }
创建接收xml请求的接口:
@Api(tags = "XmlController", description = "XmlController类 ") @Controller public class XmlController { @PostMapping(value = "/user", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE) @ResponseBody public User create(@RequestBody User user) { return user; } }