我有一个实体类:

public class Customer implements Serializable {
private static final long serialVersionUID = 1L;

@XmlTransient
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "CUSTOMER_ID")
private Integer customerId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "NAME")
private String name;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "ADDRESSLINE1")
private String addressline1;
@Basic(optional = false)
.
.
.
.

我在jax-ws网络服务中通过xml发送了此类的对象,如下所示:
<addressline1>xx</addressline1><addressline2>xx</addressline2><city>xx</city><country>xx</country><creditLimit>xx</creditLimit><customerId>xx</customerId><email>xx</email><name>xx</name><owner>xx</owner><phone>xx</phone><province>xx</province><zip>xx</zip>

是否可能不发送客户不应看到的变量之一(例如customerId)?
我已经添加了@XmlTransient,但是没有任何变化。

最佳答案

默认情况下,公共(public)属性被序列化为 XML。您需要标记相应的 get 方法 @XmlTransient 。如果您希望对字段进行注释,您可以将以下内容添加到您的类 @XmlAccessorType(XmlAccessType.FIELD) 中。

有关更多信息

  • http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html
  • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
  • 10-01 11:35