SpringBoot返回json和xml

多数情况都是返回json数据,有些情况接口需要返回的是xml数据。

如果想要返回xml数据,只需要如下操作:

    com.fasterxml.jackson.dataformat

   jackson-dataformat-xml

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 

你可能感兴趣的:(SpringBoot,spring,boot,java,spring,json)