1、pom.xml中加入
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
2、Controller中这么写
package com.example.AdcService.WebService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "Shipment")
public class ShipmentInterfaceService {
@GetMapping(value = "ShipmentInterfaceCorrectService",produces = MediaType.APPLICATION_XML_VALUE)
public String returnCorrectResponseXML(){
String xml="<?xml version=\"1.0\" encoding=\"UTF-8\" standal........";
return xml;
}
@GetMapping(value = "ShipmentInterfaceErrorService",produces = MediaType.APPLICATION_XML_VALUE)
public String returnErrorResponseXML(){
String xml="String xml=\"<?xml version=\\\"1.0......";
return xml;
}
@GetMapping(value = "/json",produces = MediaType.APPLICATION_JSON_VALUE)
public User index(){
User user = new User("dalaoyang", "26", "北京");
return user;
}
}