jaxb异常 Class has two properties of the same name username
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "User")
@XmlAccessorType(XmlAccessType.FIELD)
public class User {
private String id;
private String username;
private String password;
private Expense e;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlAttribute(name = "ID")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
This is a JAXB configuration issue, the JAXB runtime thinks there are
two properties to be serialized with the same name, one that is the
protected and field and one which is the JavaBean property method.
"If JAXB binds a class to XML, then, by default, all public members
will be bound, i.e., public getter and setter
pairs, or public fields. Any protected, package-visible or private
member is bound if it is annotated with a suitable
annotation such as XmlElement or XmlAttribute."
If you annotate your Artifact class with the annotation:
@XmlAccessorType(XmlAccessType.FIELD)
then you do not need to annotate the fields with @XmlElement and the
setter/getter methods will be ignored.
意思是jaxb的配置问题,成员变量的修饰符为public的可以不设置
@XmlAccessorType(XmlAccessType.FIELD)
如果不是public的字段需要设置此属性。
jaxb异常 Class has two properties of the same name username的更多相关文章
- maven之---资源过滤 在java/main/resourse/*.xml ,*.properties引用maven属性${db.username}
本文主要来源maven实战14.3 为了应对环境的变化,首先使用Maven属性将这个会发生变化的部分提取出来.在上一节的数据库配置中,连接数据库使用的驱动类,URL,用户名和密码都可能发生变化,因此使 ...
- Jaxb解析xml准换为javabean
先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...
- @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
@ControllerAdvice 和 @ExceptionHandler 的区别 ExceptionHandler, 方法注解, 作用于 Controller 级别. ExceptionHandle ...
- spring配置文件引入properties文件:<context:property-placeholder>标签使用总结
一.问题描述: 1.有些参数在某些阶段中是常量,比如: (1)在开发阶段我们连接数据库时的连接url.username.password.driverClass等 (2)分布式应用中client端访问 ...
- 深度分析:SpringBoot异常捕获与封装处理,看完你学会了吗?
SpringBoot异常处理 简介 日常开发过程中,难免有的程序会因为某些原因抛出异常,而这些异常一般都是利用try ,catch的方式处理异常或者throw,throws的方式抛出异常不管.这种 ...
- Liferay SDK 6.2与7.0中build.[$username].properties 文件的配置
这篇文章是针对刚开始开发Liferay的新手写的,希望能够帮到刚入门的开发者减少一些配置上的麻烦. 前提: 1. 下载了Liferay IDE(Liferay的官方开发工具) 2.下载了Liferay ...
- 9.19.3 反射和Properties(重要)
dbinfo.properties文件中的内容: driver oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@192.168.1. ...
- excel中的数据导出为properties和map的方法
在做项目的过程中,经常需要处理excel数据,特别是和业务人员配合时,业务人员喜欢使用excel处理一些数据,然后交给我们技术人员进行程序处理.利用POI读取写入excel数据,是经常使用的一个情景. ...
- javaweb 读取properties配置文件参数
场景1:在servlet中读取properties配置文件参数 protected void doGet(HttpServletRequest request, HttpServletResponse ...
随机推荐
- ZUFE OJ 2289 God Wang II
Description 这个世界太无聊了,于是God Wang想出了新的运算符号$,对于两个数x,y来说x$y的值等于x和y各个位置上的数字乘积之和,没有的位按0来算 比如说123$321=1*3+2 ...
- 基于KNN的相关内容推荐
如果做网站的内容运营,相关内容推荐可以帮助用户更快地寻找和发现感兴趣的信息,从而提升网站内容浏览的流畅性,进而提升网站的价值转化.相关内容 推荐最常见的两块就是“关联推荐”和“相关内容推荐”,关联推荐 ...
- git变基--rebase
变基过程: 两个分支 先考虑不用变基的合并: $ git checkout master $ git merge experiment 合并后: 如果变基:(以下为变基过程) $ git checko ...
- java FLOAT
System.out.println(""+ 1/2); 得不到0.5,只能得到0. 要想打印出浮点数,必须除数和被除数至少有一个是浮点数,像这样: System.out.prin ...
- php过滤提交数据 防止sql注入攻击
规则 1:绝不要信任外部数据或输入 关于 Web 应用程序安全性,必须认识到的第一件事是不应该信任外部数据.外部数据(outside data) 包括不是由程序员在 PHP 代码中直接输入的任何数据. ...
- chrome浏览器调试功能之后端篇
作为后端开发人员,可能有很多同学不怎么了解chrome调试功能,而即将成为大神的我们,怎么也得会,知其然更要知其所以然,今天我带领大家好好的梳理一下,chrome浏览器调试,个人把它分成了前端功能和后 ...
- linux下mysql root密码忘记修改方法
一.MySQL密码的恢复方法之一 如果忘记了MySQL的root密码,可以用以下方法重新设置:1.切换到root下su root 2. KILL掉系统里的MySQL进程: killall -TERM ...
- CURL C++网络延时或者最低网速下载设置
1.起因: 下载游戏更新包客户反应更新时间太久,要求我们网速比较低的时候就不要更新 2.解决: 因为之前用的是curl下载,所以在查看了curl.h里面的说明后使用了以下两个option实现了下载时最 ...
- linux ubuntu下如何安装并且切换java版本(Unsupported major.minor version 52.0)
最近在做一个dcos(数据中心操作系统)的东西,需要用marathon来做进程管理.遗憾的是0.6版本的marathon在API方面很是缺少,换成了0.15版本之后,运行时提示“Unsupported ...
- Java Interrupt Related
In Java, the main process can have several threads at a time, but only a few of them can run concurr ...