java原生xml类的两个属性具有相同名称解決方法
作者:互联网
需要在set方法上加上注解@XmlTransient
@XmlTransient 注解解决 JavaBean 属性名称与字段名称之间的名称冲突,或者用于防止字段/属性的映射
阻止将 JavaBean 属性映射到 XML 表示形式
@Data
@XmlRootElement(name = "xml")
public class BaseMessage {
@XmlElement(name = "ToUserName")
private String toUserName;
@XmlElement(name = "FromUserName")
private String fromUserName;
@XmlElement(name = "CreateTime")
private String createTime;
@XmlElement(name = "MsgType")
private String msgType;
public BaseMessage() {
}
public BaseMessage(Map<String,String> requestMap) {
this.toUserName = requestMap.get("ToUserName");
this.fromUserName = requestMap.get("FromUserName");
this.createTime = System.currentTimeMillis()/1000+"";
}
public String getToUserName() {
return toUserName;
}
@XmlTransient
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
@XmlTransient
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public String getCreateTime() {
return createTime;
}
@XmlTransient
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getMsgType() {
return msgType;
}
@XmlTransient
public void setMsgType(String msgType) {
this.msgType = msgType;
}
}
标签:xml,java,String,toUserName,createTime,解決,XmlTransient,fromUserName,public 来源: https://www.cnblogs.com/rzkwz/p/15841544.html