Constructor and Description |
---|
JAXBUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
beanToXml(Object bean)
JavaBean转换成xml
bean上面用的常用注解
|
static String |
beanToXml(Object bean,
Charset charset,
boolean format)
JavaBean转换成xml
|
static <T> T |
xmlToBean(File file,
Charset charset,
Class<T> c)
XML文件转Bean
|
static <T> T |
xmlToBean(Reader reader,
Class<T> c)
从
Reader 中读取XML字符串,并转换为Bean |
static <T> T |
xmlToBean(String xml,
Class<T> c)
xml转换成JavaBean
|
public static String beanToXml(Object bean)
bean上面用的常用注解
bean
- Bean对象{@code @XmlRootElement(name = "school")}
,
{@code @XmlElement(name = "school_name", required = true)}
,
{@code @XmlElementWrapper(name="schools")}
,
JAXB "有两个名为 "**" 的属性,类的两个属性具有相同名称 "**""解决方案
public static String beanToXml(Object bean, Charset charset, boolean format)
bean
- Bean对象charset
- 编码 eg: utf-8format
- 是否格式化输出eg: truepublic static <T> T xmlToBean(String xml, Class<T> c)
T
- Bean类型xml
- XML字符串c
- Bean类型public static <T> T xmlToBean(File file, Charset charset, Class<T> c)
T
- Bean类型file
- 文件charset
- 编码c
- Bean类Copyright © 2024. All rights reserved.