English 中文(简体)
如何在java泉水箱清单元件中添加@XmlElement
原标题:How to increment @XmlElement name in list element in java springboot

...... 产出 我需要做到:

<Entity>
<MRA_BALANCE_SHEET>
       <R0030C0030>value</R0030C0030>
       <R0030C0040>value</R0030C0040>
</MRA_BALANCE_SHEET>
<MRA_BALANCE_SHEET>
       <R0040C0030>value</R0040C0030>
       <R0040C0040>value</R0040C0030>
</MRA_BALANCE_SHEET>
</Entity>

“R0030”每个部分将增加10个。 如你在下一份清单中可以看到,R0030C0030将增加10,=“R0040C0030”

需要帮助 ......

这是我的抽样实体。

private String PHP;
        private String PHPUSD;
        
        
        @XmlJavaTypeAdapter(DynamicElementNameAdapter.class)
        public String getPHP() {
            return PHP;
        }


            

我已经尝试过这个适应者。

    public class DynamicElementNameAdapter extends XmlAdapter<String, String>{

     private static int counter = 30;
     
    @Override
    public String unmarshal(String v) throws Exception {
        // TODO Auto-generated method stub
        return v;
    }

    @Override
    public String marshal(String v) throws Exception {
            
            String dynamicElementName = "R" + String.format("%04d", counter) + "C0030";
            counter += 10; // Increment by 10 for the next element
            return dynamicElementName;
    }

}

but the output is wrong :

<Entity>
<MRA_BALANCE_SHEET>
       <PHP>R0030C0030</PHP>
</MRA_BALANCE_SHEET>
<MRA_BALANCE_SHEET>
       <PHP>R0040C0030</PHP>
</MRA_BALANCE_SHEET>
</Entity>

!

问题回答

You should create a map of your element name as key and element value as value. Then, you can use XStream or any other library to convert this map to xml.

。 • 如何将XML转化为 j。 地图,反之亦然?用于更多的信息。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签