<dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </dependency> public class User { private String name; private int age; } XmlMapper xmlMapper = new XmlMapper(); try { User user = xmlMapper.readValue(xmlString, User.class); System.out.println(user.getName()); System.out.println(user.getAge()); } catch (IOException e) { e.printStackTrace(); } XmlMapper xmlMapper = new XmlMapper(); try { String xmlString = xmlMapper.writeValueAsString(user); System.out.println(xmlString); } catch (JsonProcessingException e) { e.printStackTrace(); }


上一篇:
下一篇:
切换中文