我正在使用 spring 框架 3.1(带有休眠),并且我正在尝试生成 XML 表示形式,例如:
<user>
<iduser>1</iduser>
<email>bla@hello.com</email>
<firstName>bob</firstName>
</user>
从这个java类:
@Entity
public class User {
@GenericGenerator(name = "table-hilo-generator", strategy = "org.hibernate.id.IncrementGenerator")
@GeneratedValue(generator = "table-hilo-generator")
@Id
@Column(name = "iduser", unique = true, nullable = false)
private int iduser;
@NotBlank
@NotNull
@NotEmpty
@Length(max = EMAIL_MAX_SIZE)
@Column(name = "email", nullable = false)
private String email;
@NotBlank
@NotNull
@NotEmpty
@Length(max = FIRST_NAME_MAX_SIZE)
@Column(name = "firstName", nullable = false)
private String firstName;
}
我的 servlet-conf.xml 在 ContentNegotiatingViewResolver 中包含此视图:
<!-- XML View -->
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="aliases">
<map>
<entry key="user123" value="com.....entities.User" />
</map>
</property>
</bean>
</constructor-arg>
</bean>
但我不明白为什么结果是一个包含数百个元素的奇怪 xml,例如:
<org.springframework.validation.BeanPropertyBindingResult>
<nestedPath/>
<nestedPathStack serialization="custom">
<unserializable-parents/>
<vector>
<default>
<capacityIncrement>0</capacityIncrement>
<elementCount>0</elementCount>
<elementData>
<null/>
<null/>
<null/>
<null/>
<null/>
<null/>
<null/>
<null/>
<null/>
<null/>
</elementData>
</default>
</vector>
</nestedPathStack>
<objectName>user</objectName>
<messageCodesResolver class="org.springframework.validation.DefaultMessageCodesResolver">
<prefix/>
1-可能是编组器对反射玩得太多了,我怎样才能获得我想要的预期结果?(2-我也有兴趣生成一个包含用户列表的 XML 文件)我该怎么做?