多数情况都是返回json数据,有些情况接口需要返回的是xml数据。
如果想要返回xml数据,只需要如下操作:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
import org.spring.springboot.domain.City;
import org.spring.springboot.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.MediaType;
@RestController
public class CityRestController {
@Autowired
private CityService cityService;
//返回json
@RequestMapping(value = "/api/city", method