mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
* 【poi 】 ExcelBase增加renameSheet、cloneSheet(issue#I466ZZ@Gitee)
|
* 【poi 】 ExcelBase增加renameSheet、cloneSheet(issue#I466ZZ@Gitee)
|
||||||
* 【core 】 ListUtil增加splitAvg方法(pr#397@Gitee)
|
* 【core 】 ListUtil增加splitAvg方法(pr#397@Gitee)
|
||||||
* 【poi 】 Excel07SaxReader支持数字类型sheet名称、支持sheetName:名称前缀(issue#I46OMA@Gitee)
|
* 【poi 】 Excel07SaxReader支持数字类型sheet名称、支持sheetName:名称前缀(issue#I46OMA@Gitee)
|
||||||
|
* 【extra 】 Mail增加build方法(issue#I46LGE@Gitee)
|
||||||
|
* 【core 】 XmlUtil增加beanToXml重载,支持忽略null
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复MapUtil.sort比较器不一致返回原map的问题(issue#I46AQJ@Gitee)
|
* 【core 】 修复MapUtil.sort比较器不一致返回原map的问题(issue#I46AQJ@Gitee)
|
||||||
|
@@ -1270,10 +1270,25 @@ public class XmlUtil {
|
|||||||
* @since 5.2.4
|
* @since 5.2.4
|
||||||
*/
|
*/
|
||||||
public static Document beanToXml(Object bean, String namespace) {
|
public static Document beanToXml(Object bean, String namespace) {
|
||||||
|
return beanToXml(bean, namespace, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Bean转换为XML
|
||||||
|
*
|
||||||
|
* @param bean Bean对象
|
||||||
|
* @param namespace 命名空间,可以为null
|
||||||
|
* @param ignoreNull 时候忽略值为{@code null}的属性
|
||||||
|
* @return XML
|
||||||
|
* @see JAXBUtil#beanToXml(Object)
|
||||||
|
* @since 5.7.10
|
||||||
|
*/
|
||||||
|
public static Document beanToXml(Object bean, String namespace, boolean ignoreNull) {
|
||||||
if (null == bean) {
|
if (null == bean) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return mapToXml(BeanUtil.beanToMap(bean), bean.getClass().getSimpleName(), namespace);
|
return mapToXml(BeanUtil.beanToMap(bean, false, ignoreNull),
|
||||||
|
bean.getClass().getSimpleName(), namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -195,6 +195,33 @@ public class XmlUtilTest {
|
|||||||
Assert.assertEquals("2020/04/15 21:01:21", value);
|
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
|
@Test
|
||||||
public void xmlToBeanTest() {
|
public void xmlToBeanTest() {
|
||||||
@Data
|
@Data
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package cn.hutool.extra.mail;
|
package cn.hutool.extra.mail;
|
||||||
|
|
||||||
|
import cn.hutool.core.builder.Builder;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
@@ -34,7 +35,7 @@ import java.util.Date;
|
|||||||
* @author looly
|
* @author looly
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
*/
|
*/
|
||||||
public class Mail {
|
public class Mail implements Builder<MimeMessage> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱帐户信息以及一些客户端配置信息
|
* 邮箱帐户信息以及一些客户端配置信息
|
||||||
@@ -364,6 +365,15 @@ public class Mail {
|
|||||||
}
|
}
|
||||||
// --------------------------------------------------------------- Getters and Setters end
|
// --------------------------------------------------------------- Getters and Setters end
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MimeMessage build() {
|
||||||
|
try {
|
||||||
|
return buildMsg();
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
throw new MailException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送
|
* 发送
|
||||||
*
|
*
|
||||||
|
@@ -357,7 +357,7 @@ public class MailUtil {
|
|||||||
* @return {@link Session}
|
* @return {@link Session}
|
||||||
* @since 5.5.7
|
* @since 5.5.7
|
||||||
*/
|
*/
|
||||||
public static Session getSession(MailAccount mailAccount, boolean isSingleton){
|
public static Session getSession(MailAccount mailAccount, boolean isSingleton) {
|
||||||
Authenticator authenticator = null;
|
Authenticator authenticator = null;
|
||||||
if (mailAccount.isAuth()) {
|
if (mailAccount.isAuth()) {
|
||||||
authenticator = new UserPassAuthenticator(mailAccount.getUser(), mailAccount.getPass());
|
authenticator = new UserPassAuthenticator(mailAccount.getUser(), mailAccount.getPass());
|
||||||
|
Reference in New Issue
Block a user