add method

This commit is contained in:
Looly 2022-02-22 22:56:00 +08:00
parent 4e3f2153c5
commit 74d9f0e586
3 changed files with 37 additions and 2 deletions

View File

@ -12,6 +12,7 @@
* 【core 】 使多个xxxBuilder实现Builder接口扩展CheckedUtilpr#545@Gitee
* 【core 】 CheckedUtil删除第二个参数为RuntimeException的方法
* 【core 】 FileUtil增加getTotalLines方法
* 【db 】 MetaUtil增加getTableMeta重载issue#2157@Github
### 🐞Bug修复
* 【cache 】 修复ReentrantCache.toString方法线程不安全问题issue#2140@Github

View File

@ -1,9 +1,12 @@
package cn.hutool.core.date;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.Date;
public class ChineseDateTest {
@Test
@ -113,4 +116,12 @@ public class ChineseDateTest {
final String chineseMonth = springFestival.getChineseMonth();
Assert.assertEquals("一月", chineseMonth);
}
@Test
public void dayTest(){
Date date = DateUtil.parse("1900-01-31");
//Date date = DateUtil.parse("2022-02-22","yyyy-MM-dd");
ChineseDate chineseDate = new ChineseDate(date);
Console.log(chineseDate);
}
}

View File

@ -185,15 +185,38 @@ public class MetaUtil {
* @return Table对象
*/
public static Table getTableMeta(DataSource ds, String tableName) {
return getTableMeta(ds, null, null, tableName);
}
/**
* 获得表的元信息<br>
* 注意如果需要获取注释某些数据库如MySQL需要在配置中添加:
* <pre>
* remarks = true
* useInformationSchema = true
* </pre>
*
* @param ds 数据源
* @param tableName 表名
* @param catalog catalog name{@code null}表示自动获取{@link #getCataLog(Connection)}
* @param schema a schema name pattern{@code null}表示自动获取{@link #getSchema(Connection)}
* @return Table对象
* @since 5.7.22
*/
public static Table getTableMeta(DataSource ds, String catalog, String schema, String tableName) {
final Table table = Table.create(tableName);
Connection conn = null;
try {
conn = ds.getConnection();
// catalog和schema获取失败默认使用null代替
final String catalog = getCataLog(conn);
if(null == catalog){
catalog = getCataLog(conn);
}
table.setCatalog(catalog);
final String schema = getSchema(conn);
if(null == schema){
schema = getSchema(conn);
}
table.setSchema(schema);
final DatabaseMetaData metaData = conn.getMetaData();