从 xml、spring-boot 解组映射内部 类

castors unmarshalling mapping internal classes from xml, spring-boot

我有一个 xml 文件,我使用脚轮解组映射到 2 java classes。目前看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<Configurations>
    <Port>8007</Port>
    <EnableHttps>true</EnableHttps>
    <KeyStorePath>classpath:ssl-server.jks</KeyStorePath>
    <KeyPass>changeit</KeyPass>
    <TokenTtlMillis>15000</TokenTtlMillis>
  <Users>
    <Username>user1</Username>
    <Password>a$kIWaw2g1w0TC.RUtr1k3nu3PBZ9qtaLvAMhFmtbF2X8cwiXC9OXhS</Password> <!-- password -->
  </Users>
  <Users>
    <Username>user2</Username>
    <Password>a$jxGxonindJQgZjQoRxDhPewFjOo0F3ZoU8.VOFEOHTuMIJHRVTyF6</Password> <!-- password2 -->
  </Users>
</Configurations>

现在我想把我的 <users> 包裹在另一个 <users> 中,所以它看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<Configurations>
  <Port>8007</Port>
  <EnableHttps>true</EnableHttps>
  <KeyStorePath>classpath:ssl-server.jks</KeyStorePath>
  <KeyPass>changeit</KeyPass>
  <TokenTtlMillis>15000</TokenTtlMillis>
  <Users>
    <User>
      <Username>user1</Username>
      <Password>a$kIWaw2g1w0TC.RUtr1k3nu3PBZ9qtaLvAMhFmtbF2X8cwiXC9OXhS</Password> <!-- password -->
    </User>
    <User>
      <Username>user2</Username>
      <Password>a$jxGxonindJQgZjQoRxDhPewFjOo0F3ZoU8.VOFEOHTuMIJHRVTyF6</Password> <!-- password2 -->
    </User>
  </Users>
</Configurations>

如何在映射文件中执行此操作?目前看起来像这样,其中 1 class 有另一个 class

的列表
<mapping>
  <class name="com.cetrea.securityservice.bean.Configurations" auto-complete="true">
    <map-to xml="Configurations"/>
    <field name="port" type="int">
      <bind-xml name="Port" node="element"/>
    </field>
    <field name="enableHttps" type="boolean">
      <bind-xml name="EnableHttps" node="element"/>
    </field>
    <field name="keyStorePath" type="string">
      <bind-xml name="KeyStorePath" node="element"/>
    </field>
    <field name="keyPass" type="string">
      <bind-xml name="KeyPass" node="element"/>
    </field>
    <field name="TTL" type="int">
      <bind-xml name="TokenTtlMillis" node="element"/>
    </field>
    <field name="Users" collection="arraylist" type="com.cetrea.securityservice.bean.Users">
      <bind-xml name="Users"/>
    </field>
  </class>
  <class name="com.cetrea.securityservice.bean.Users" auto-complete="true">
    <map-to xml="Users"/>
    <field name="Username" type="string">
      <bind-xml name="Username" node="element"/>
    </field>
    <field name="Password" type="string">
      <bind-xml name="Password" node="element"/>
    </field>
  </class>
</mapping>

我想我需要配置 class,有一个字段是用户 class,然后用户 class 需要有一个用户列表。但我真的无法理解如何实施它,以及我的 java 模型 classes

中需要更改的内容

我在List下这样添加了<location="Users">映射文件。这会创建一个包装器,不需要在模型中 类

<mapping>
  <class name="com.cetrea.securityservice.bean.Configurations" auto-complete="true">
    <map-to xml="Configurations"/>
    <field name="port" type="int">
      <bind-xml name="Port" node="element"/>
    </field>
    <field name="enableHttps" type="boolean">
      <bind-xml name="EnableHttps" node="element"/>
    </field>
    <field name="keyStorePath" type="string">
      <bind-xml name="KeyStorePath" node="element"/>
    </field>
    <field name="keyPass" type="string">
      <bind-xml name="KeyPass" node="element"/>
    </field>
    <field name="TTL" type="int">
      <bind-xml name="TokenTtlMillis" node="element"/>
    </field>
    <field name="Users" collection="arraylist" type="com.cetrea.securityservice.bean.Users">
      <bind-xml name="User" location="Users"/>
    </field>
  </class>
  <class name="com.cetrea.securityservice.bean.Users" auto-complete="true">
    <map-to xml="User"/>
    <field name="Username" type="string">
      <bind-xml name="Username" node="element"/>
    </field>
    <field name="Password" type="string">
      <bind-xml name="Password" node="element"/>
    </field>
  </class>
</mapping>