zoukankan      html  css  js  c++  java
  • SpringBoot支持Xml数据格式显示

    第一步:pom文件添加依赖

    <dependency>
         <groupId>com.fasterxml.jackson.dataformat</groupId>
         <artifactId>jackson-dataformat-xml</artifactId>
    </dependency>

    第二步:将返回的对象添加相应的注解

    package com.example.domain;
    
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    public class Student {
        private String name;
        private int age;
        private char sex;
    
        @XmlElement
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
        @XmlElement
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
        @XmlElement
        public char getSex() {
            return sex;
        }
    
        public void setSex(char sex) {
            this.sex = sex;
        }
        
        
        
    }

    第三步:控制器方法

    /**
         * 测试返回xml格式数据
         * 第一步:
         * @return
         */
        @ResponseBody
        @RequestMapping( value="xml", produces= { MediaType.APPLICATION_XML_VALUE } )
        public Student sayHelloXml() {
            Student stu = new Student();
            stu.setName("Xml");
            stu.setAge(10);
            stu.setSex('女');
            return stu;
        }

    结果显示:

  • 相关阅读:
    Go断后,Dart冲前,Google的野心
    gcc dynamic load library
    Go http server 高并发
    还是Go 为了伟大的未来
    windows go dll 框架
    Go cookie
    Go web ajax project
    hdoj 2844 Coins
    hdoj 1203 I NEED A OFFER!
    hdoj 2546 饭卡
  • 原文地址:https://www.cnblogs.com/ysq2018China/p/10241102.html
Copyright © 2011-2022 走看看