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>
相关推荐
哎呀呦呵17 小时前
python内置模块-re模块介绍使用
java·python·mysql
louisgeek17 小时前
Java CompletableFuture
java
ะัี潪ิื17 小时前
精灵图(雪碧图)的生成和使用
java·css
web安全工具库17 小时前
从课堂笔记到实践:深入理解Linux C函数库的奥秘
java·数据库·算法
ss27317 小时前
手写MyBatis第104弹:SqlSession从工厂构建到执行器选择的深度剖析
java·开发语言·后端·mybatis
周杰伦_Jay18 小时前
【Java集合体系】全面解析:架构、原理与实战选型
java·开发语言·数据结构·链表·架构
Camel卡蒙18 小时前
DDD架构——实体、聚合、值对象
java·开发语言·架构
青云交18 小时前
Java 大视界 -- 基于 Java 的大数据实时流处理在智能电网分布式电源接入与电力系统稳定性维护中的应用
java·分布式电源·智能电网·java 大数据·flink 实时流处理·kafka 数据采集·iec 61850 协议
失散1318 小时前
分布式专题——41 RocketMQ集群高级特性
java·分布式·架构·rocketmq
失散1318 小时前
分布式专题——42 MQ常见问题梳理
java·分布式·架构