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 ...
随机推荐
- VBS一键配置VOIP脚本(其中包括VBS操作JS网页中的按钮事件--直接执行确认按钮中的脚本代码)
Dim ws,fso,IESet IE = WScript.createobject("InternetExplorer.Application")Set ws = WScript ...
- JS总结之一:字符串的调用方法
字符串的调用方法:var s="hello, world";document.write(s.charAt(0)); //第一个字符document.write(s.charAt( ...
- 缓存1 静态缓存-->读库保存成php文件 mkdir-->file_put_contents-->var_export -->include
@mkdir()-->file_put_contents-->$data = "<?php\nreturn ".var_export($setting, tru ...
- redis第一篇--综述
1 redis里边有数据库的概念.可分为1-255这些表.在存储或者查找的时候要指明. redis_sentinel 集群里边封装成了namespace这样的概念.与db是不一样的.
- tar解压
tar在linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数: -c :create 建立压缩档案的参数:-x : 解压缩压缩档案的参数:-z : 是否需 ...
- Android Studio 如何将包名按层级展示
在project视图右上角有个“设置”的按钮,点开,然后将上图所圈部分去勾选就可以了.
- nginx 正则表达式
1.nginx配置基础 1.正则表达式匹配 ~ 区分大小写匹配 ~* 不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 ^ 以什么开头的匹配 $ 以什么结尾的匹配 转义字符.可 ...
- zf-删除重复数据只保留一条(转)
http://blog.csdn.net/anya/article/details/6407280
- 巧妙利用ToArray()函数移除集合中的元素
当我们对集合foreach遍历时,不能直接移除遍历的集合的元素,解决的方法有很多种,见我之前的随笔: http://www.cnblogs.com/527289276qq/p/4331000.html ...
- php的错误和异常处理
php中try catch的例子: <?php try { if (@mysql_connect('localhost','root','123456')){ // echo 'success! ...