Spring MVC返回XML

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013560667/article/details/88191669
@RequestMapping(value = "/path", produces = "application/xml;charset=UTF-8")
	@ResponseBody
	public String getFlowCacheWithXml(String svcCode) {
		Bean obj=...
		String xml = "";
		try {
			XStream xStream = new XStream();
			xStream.alias("BeanType", BeanType.class);
			xml = xStream.toXML(obj);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return xml;
	}
<dependency>
			<groupId>com.thoughtworks.xstream</groupId>
			<artifactId>xstream</artifactId>
			<version>${xstream.version}</version>
		</dependency>

猜你喜欢

转载自blog.csdn.net/u013560667/article/details/88191669