mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix timestamp bug
This commit is contained in:
parent
8fda7fe8bd
commit
4663e0d175
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复TypeUtil无法获取泛型接口的泛型参数问题(issue#I1BRFI@Gitee)
|
* 【core 】 修复TypeUtil无法获取泛型接口的泛型参数问题(issue#I1BRFI@Gitee)
|
||||||
|
* 【core 】 修复MySQL中0000报错问题
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
## 5.2.3
|
## 5.2.3
|
||||||
|
@ -3,6 +3,7 @@ package cn.hutool.core.lang.tree;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -44,6 +45,57 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Comparable
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ID对应的节点,如果有多个ID相同的节点,只返回第一个。<br>
|
||||||
|
* 此方法只查找此节点及子节点,采用广度优先遍历。
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
* @return 节点
|
||||||
|
* @since 5.2.4
|
||||||
|
*/
|
||||||
|
public Tree<T> getNode(T id) {
|
||||||
|
if (ObjectUtil.equal(id, getId())) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找子节点
|
||||||
|
Tree<T> node;
|
||||||
|
for (Tree<T> child : getChildren()) {
|
||||||
|
node = child.getNode(id);
|
||||||
|
if (null != node) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 未找到节点
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有父节点名称列表
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 比如有个人在研发1部,他上面有研发部,接着上面有技术中心<br>
|
||||||
|
* 返回结果就是:[研发一部, 研发中心, 技术中心]
|
||||||
|
*
|
||||||
|
* @param includeCurrentNode 是否包含当前节点的名称
|
||||||
|
* @return 所有父节点名称列表
|
||||||
|
* @since 5.2.4
|
||||||
|
*/
|
||||||
|
public List<CharSequence> getParentsName(boolean includeCurrentNode) {
|
||||||
|
final List<CharSequence> result = new ArrayList<>();
|
||||||
|
if (includeCurrentNode) {
|
||||||
|
result.add(this.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
Tree<T> parent = getParent();
|
||||||
|
while (null != parent) {
|
||||||
|
result.add(parent.getName());
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置父节点
|
* 设置父节点
|
||||||
*
|
*
|
||||||
@ -52,7 +104,7 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Comparable
|
|||||||
*/
|
*/
|
||||||
public Tree<T> setParent(Tree<T> parent) {
|
public Tree<T> setParent(Tree<T> parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
if(null != parent){
|
if (null != parent) {
|
||||||
this.setParentId(parent.getId());
|
this.setParentId(parent.getId());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -94,12 +146,11 @@ public class Tree<T> extends LinkedHashMap<String, Object> implements Comparable
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public CharSequence getName() {
|
||||||
public T getName() {
|
return (CharSequence) this.get(treeNodeConfig.getNameKey());
|
||||||
return (T) this.get(treeNodeConfig.getNameKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tree<T> setName(Object name) {
|
public Tree<T> setName(CharSequence name) {
|
||||||
this.put(treeNodeConfig.getNameKey(), name);
|
this.put(treeNodeConfig.getNameKey(), name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -265,15 +265,14 @@ public class HandleHelper {
|
|||||||
* @throws SQLException SQL异常
|
* @throws SQLException SQL异常
|
||||||
*/
|
*/
|
||||||
private static <T> Object getColumnValue(ResultSet rs, int columnIndex, int type, Type targetColumnType) throws SQLException {
|
private static <T> Object getColumnValue(ResultSet rs, int columnIndex, int type, Type targetColumnType) throws SQLException {
|
||||||
Object rawValue;
|
Object rawValue = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Types.TIMESTAMP:
|
case Types.TIMESTAMP:
|
||||||
try{
|
try{
|
||||||
rawValue = rs.getTimestamp(columnIndex);
|
rawValue = rs.getTimestamp(columnIndex);
|
||||||
} catch (SQLException ignore){
|
} catch (SQLException ignore){
|
||||||
// issue#776@Github
|
// issue#776@Github
|
||||||
// 当数据库中日期为0000-00-00 00:00:00报错,按照普通日期获取
|
// 当数据库中日期为0000-00-00 00:00:00报错,转为null
|
||||||
rawValue = rs.getDate(columnIndex);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Types.TIME:
|
case Types.TIME:
|
||||||
|
@ -5,6 +5,7 @@ import org.junit.Ignore;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MySQL操作单元测试
|
* MySQL操作单元测试
|
||||||
@ -26,11 +27,11 @@ public class MySQLTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事务测试<br>
|
* 事务测试<br>
|
||||||
* 更新三条信息,低2条后抛出异常,正常情况下三条都应该不变
|
* 更新三条信息,低2条后抛出异常,正常情况下三条都应该不变
|
||||||
*
|
*
|
||||||
* @throws SQLException SQL异常
|
* @throws SQLException SQL异常
|
||||||
*/
|
*/
|
||||||
@Test(expected=SQLException.class)
|
@Test(expected=SQLException.class)
|
||||||
@ -56,4 +57,11 @@ public class MySQLTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void getTimeStampTest() throws SQLException {
|
||||||
|
final List<Entity> all = Db.use("mysql").findAll("test");
|
||||||
|
Console.log(all);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ user = looly
|
|||||||
pass = 123456
|
pass = 123456
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
url = jdbc:mysql://looly.centos:3306/test_hutool?useSSL=false
|
url = jdbc:mysql://looly.centos8:3306/hutool_test?useSSL=false
|
||||||
user = root
|
user = root
|
||||||
pass = 123456
|
pass = 123456
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user