XmlElement注解用在Java的列表属性上产生的效果

例如,下面的代码,XmlElement注解用在了Conditions类的conditionList属性的getter方法上,其中conditionList是一个列表类型:

package com.thb;

import java.util.List;

import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlValue;

// 映射到xml中的conditions元素
@XmlRootElement(name = "conditions")
@XmlType(propOrder = {"conditionList"})
public class Conditions {

    /**
     * 查询条件列表
     */
    private List<Conditions.Condition> conditionList;

    @XmlElement(name = "condition")
    public List<Conditions.Condition> getconditionList(){
        return this.conditionList;
    }

    public void setCondition( List<Conditions.Condition> conditionList) {
        this.conditionList = conditionList;
    }


    @XmlType(propOrder = {"value"})
    public static class Condition {

        private String value;
        /**
         * 属性名称
         */
        private String name;
        /**
         * 属性类型
         */
        private String type;

        /**
         * 获取value的值
         */
        @XmlValue
        public String getValue() {
            return this.value;
        }

        /**
         * 给value赋值
         * @param value
         */
        public void setValue(String value) {
            this.value = value;
        }

        /**
         * 获取name的值
         */
        @XmlAttribute(name = "name")
        public String getName() {
            return this.name;
        }

        /**
         * 给name赋值
         * @param name
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * 获取type的值
         */
        @XmlAttribute(name = "type")
        public String getType() {
            return this.type;
        }

        /**
         * 给type赋值
         * @param type
         */
        public void setType(String type) {
            this.type = type;
        }
    }
}

产生的XML Schema如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="conditions" type="conditions"/>

  <xs:complexType name="conditions">
    <xs:sequence>
      <xs:element name="condition" type="condition" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="condition">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="type" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:schema>
相关推荐
试行4 分钟前
Android实现自定义下拉列表绑定数据
android·java
茜茜西西CeCe10 分钟前
移动技术开发:简单计算器界面
java·gitee·安卓·android-studio·移动技术开发·原生安卓开发
救救孩子把14 分钟前
Java基础之IO流
java·开发语言
小菜yh16 分钟前
关于Redis
java·数据库·spring boot·redis·spring·缓存
宇卿.22 分钟前
Java键盘输入语句
java·开发语言
浅念同学23 分钟前
算法.图论-并查集上
java·算法·图论
立志成为coding大牛的菜鸟.36 分钟前
力扣1143-最长公共子序列(Java详细题解)
java·算法·leetcode
鱼跃鹰飞36 分钟前
Leetcode面试经典150题-130.被围绕的区域
java·算法·leetcode·面试·职场和发展·深度优先
爱上语文2 小时前
Springboot的三层架构
java·开发语言·spring boot·后端·spring
serve the people2 小时前
springboot 单独新建一个文件实时写数据,当文件大于100M时按照日期时间做文件名进行归档
java·spring boot·后端