名称/值对的 Castor 编组
我有一个简单的 POJO,其中包含一个名称/值对:
public class Parameter {
private String name = null;
private String value = null;
public Parameter() {
// Do Nothing
}
public Parameter(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
我想将其编组到一个如下所示的 XML 结构中:
<parameter name="P3">Parameter 3</parameter>
我尝试了一个看起来像这样的映射,但它不起作用:
<class name="pkg.Parameter">
<field name="Name">
<bind-xml name="name" node="attribute" />
</field>
<field name="Value">
<bind-xml name="paramValue"/>
</field>
</class>
它给了我这个:
<parameter name="P3">
<paramValue>Parameter 3</paramValue>
</parameter>
差不多就这样了但这个值显然放错了地方。本质上我希望从 Parameter.getValue() 返回的值形成
这应该很简单,我相信它会很简单,但我似乎无法做到这一点。
有什么想法吗?
I have a simple POJO that contains a name/value pair:
public class Parameter {
private String name = null;
private String value = null;
public Parameter() {
// Do Nothing
}
public Parameter(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
I want to marshall this into an XML structure that looks like this:
<parameter name="P3">Parameter 3</parameter>
I've tried a mapping that looks like this but it's not working:
<class name="pkg.Parameter">
<field name="Name">
<bind-xml name="name" node="attribute" />
</field>
<field name="Value">
<bind-xml name="paramValue"/>
</field>
</class>
It gives me this:
<parameter name="P3">
<paramValue>Parameter 3</paramValue>
</parameter>
That's almost there but the value is obviously misplaced. Essentially I want the value returned from Parameter.getValue() to form the content of the <parameter> element rather than a subelement.
This should be simple, and I'm sure it will be, but I can't seem to get there.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,好悲伤。就好像花时间解释问题会重新组织你大脑中的一切,点击“发布”后解决方案就会出现!
事实证明,我需要做的就是更改
为
完成后,我现在看到的是:
史蒂夫
Oh good grief. It's as if taking the time to explain the problem reorganises everthing in your brain and the solution comes to you just after clicking "Post"!
It turns out that all I needed to do was change
to
Having done that I'm now seeing this:
Steve