mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add method
This commit is contained in:
@@ -195,6 +195,33 @@ public class XmlUtilTest {
|
||||
Assert.assertEquals("2020/04/15 21:01:21", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanToXmlIgnoreNullTest() {
|
||||
@Data
|
||||
class TestBean {
|
||||
private String ReqCode;
|
||||
private String AccountName;
|
||||
private String Operator;
|
||||
private String ProjectCode;
|
||||
private String BankCode;
|
||||
}
|
||||
|
||||
final TestBean testBean = new TestBean();
|
||||
testBean.setReqCode("1111");
|
||||
testBean.setAccountName("账户名称");
|
||||
testBean.setOperator("cz");
|
||||
testBean.setProjectCode(null);
|
||||
testBean.setBankCode("00001");
|
||||
|
||||
// 不忽略空字段情况下保留自闭标签
|
||||
Document doc = XmlUtil.beanToXml(testBean, null, false);
|
||||
Assert.assertNotNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode"));
|
||||
|
||||
// 忽略空字段情况下无自闭标签
|
||||
doc = XmlUtil.beanToXml(testBean, null, true);
|
||||
Assert.assertNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlToBeanTest() {
|
||||
@Data
|
||||
|
Reference in New Issue
Block a user