1.上代码
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class XmlController {
@RequestMapping(value = "/xml", produces={"application/xml; charset=UTF-8"}, method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public String xml(HttpServletRequest request, HttpServletResponse response)
throws Exception {
String xmlData = "<person>"
+ "<name>tom</name>"
+ "<age>17</age>"
+ "</person>";
return xmlData;
}
}
2.springmvc配置文件如下: