mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
373c30b9f0
commit
8c3298fed4
@ -1819,6 +1819,18 @@ public class CharSequenceUtil {
|
|||||||
return StrSplitter.split(str.toString(), separator, limit, isTrim, ignoreEmpty);
|
return StrSplitter.split(str.toString(), separator, limit, isTrim, ignoreEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切分字符串,如果分隔符不存在则返回原字符串
|
||||||
|
*
|
||||||
|
* @param str 被切分的字符串
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 字符串
|
||||||
|
* @since 5.7.1
|
||||||
|
*/
|
||||||
|
public static List<String> split(CharSequence str, CharSequence separator) {
|
||||||
|
return split(str, separator, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切分字符串
|
* 切分字符串
|
||||||
*
|
*
|
||||||
|
@ -386,7 +386,6 @@ public class IdcardUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 首字母A-Z,A表示1,以此类推
|
// 首字母A-Z,A表示1,以此类推
|
||||||
char start = idcard.charAt(0);
|
|
||||||
String mid = card.substring(1, 7);
|
String mid = card.substring(1, 7);
|
||||||
String end = card.substring(7, 8);
|
String end = card.substring(7, 8);
|
||||||
char[] chars = mid.toCharArray();
|
char[] chars = mid.toCharArray();
|
||||||
|
@ -73,7 +73,7 @@ public class BeanUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fillBeanWithMapIgnoreCaseTest() {
|
public void fillBeanWithMapIgnoreCaseTest() {
|
||||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("Name", "Joe");
|
map.put("Name", "Joe");
|
||||||
map.put("aGe", 12);
|
map.put("aGe", 12);
|
||||||
map.put("openId", "DFDFSDFWERWER");
|
map.put("openId", "DFDFSDFWERWER");
|
||||||
@ -104,7 +104,7 @@ public class BeanUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void toBeanIgnoreErrorTest() {
|
public void toBeanIgnoreErrorTest() {
|
||||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("name", "Joe");
|
map.put("name", "Joe");
|
||||||
// 错误的类型,此处忽略
|
// 错误的类型,此处忽略
|
||||||
map.put("age", "aaaaaa");
|
map.put("age", "aaaaaa");
|
||||||
@ -117,7 +117,7 @@ public class BeanUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapToBeanIgnoreCaseTest() {
|
public void mapToBeanIgnoreCaseTest() {
|
||||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("Name", "Joe");
|
map.put("Name", "Joe");
|
||||||
map.put("aGe", 12);
|
map.put("aGe", 12);
|
||||||
|
|
||||||
@ -128,12 +128,12 @@ public class BeanUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapToBeanTest() {
|
public void mapToBeanTest() {
|
||||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("a_name", "Joe");
|
map.put("a_name", "Joe");
|
||||||
map.put("b_age", 12);
|
map.put("b_age", 12);
|
||||||
|
|
||||||
// 别名,用于对应bean的字段名
|
// 别名,用于对应bean的字段名
|
||||||
HashMap<String, String> mapping = CollUtil.newHashMap();
|
HashMap<String, String> mapping = MapUtil.newHashMap();
|
||||||
mapping.put("a_name", "name");
|
mapping.put("a_name", "name");
|
||||||
mapping.put("b_age", "age");
|
mapping.put("b_age", "age");
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class BeanUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void mapToBeanTest2() {
|
public void mapToBeanTest2() {
|
||||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("name", "Joe");
|
map.put("name", "Joe");
|
||||||
map.put("age", 12);
|
map.put("age", 12);
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ public class ListUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterTest(){
|
public void editTest(){
|
||||||
List<String> a = ListUtil.toLinkedList("1", "2", "3");
|
List<String> a = ListUtil.toLinkedList("1", "2", "3");
|
||||||
final List<String> filter = ListUtil.filter(a, str -> "edit" + str);
|
final List<String> filter = ListUtil.edit(a, str -> "edit" + str);
|
||||||
Assert.assertEquals("edit1", filter.get(0));
|
Assert.assertEquals("edit1", filter.get(0));
|
||||||
Assert.assertEquals("edit2", filter.get(1));
|
Assert.assertEquals("edit2", filter.get(1));
|
||||||
Assert.assertEquals("edit3", filter.get(2));
|
Assert.assertEquals("edit3", filter.get(2));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.hutool.cron;
|
package cn.hutool.cron;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.thread.ExecutorBuilder;
|
import cn.hutool.core.thread.ExecutorBuilder;
|
||||||
import cn.hutool.core.thread.ThreadFactoryBuilder;
|
import cn.hutool.core.thread.ThreadFactoryBuilder;
|
||||||
import cn.hutool.core.util.CharUtil;
|
import cn.hutool.core.util.CharUtil;
|
||||||
@ -180,7 +180,7 @@ public class Scheduler implements Serializable {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public Scheduler schedule(Setting cronSetting) {
|
public Scheduler schedule(Setting cronSetting) {
|
||||||
if (CollUtil.isNotEmpty(cronSetting)) {
|
if (MapUtil.isNotEmpty(cronSetting)) {
|
||||||
String group;
|
String group;
|
||||||
for (Entry<String, LinkedHashMap<String, String>> groupedEntry : cronSetting.getGroupedMap().entrySet()) {
|
for (Entry<String, LinkedHashMap<String, String>> groupedEntry : cronSetting.getGroupedMap().entrySet()) {
|
||||||
group = groupedEntry.getKey();
|
group = groupedEntry.getKey();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.ds.DSFactory;
|
import cn.hutool.db.ds.DSFactory;
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class DaoTemplate {
|
|||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> int del(Entity where) throws SQLException {
|
public <T> int del(Entity where) throws SQLException {
|
||||||
if (CollectionUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return db.del(fixEntity(where));
|
return db.del(fixEntity(where));
|
||||||
@ -163,7 +163,7 @@ public class DaoTemplate {
|
|||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(Entity record, Entity where) throws SQLException{
|
public int update(Entity record, Entity where) throws SQLException{
|
||||||
if (CollectionUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return db.update(fixEntity(record), where);
|
return db.update(fixEntity(record), where);
|
||||||
@ -176,7 +176,7 @@ public class DaoTemplate {
|
|||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public int update(Entity entity) throws SQLException {
|
public int update(Entity entity) throws SQLException {
|
||||||
if (CollectionUtil.isEmpty(entity)) {
|
if (MapUtil.isEmpty(entity)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
entity = fixEntity(entity);
|
entity = fixEntity(entity);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.dialect.Dialect;
|
import cn.hutool.db.dialect.Dialect;
|
||||||
@ -99,7 +99,7 @@ public class DialectRunner implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public <T> T insert(Connection conn, Entity record, RsHandler<T> generatedKeysHandler) throws SQLException {
|
public <T> T insert(Connection conn, Entity record, RsHandler<T> generatedKeysHandler) throws SQLException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (CollUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
throw new SQLException("Empty entity provided!");
|
throw new SQLException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ public class DialectRunner implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public int del(Connection conn, Entity where) throws SQLException {
|
public int del(Connection conn, Entity where) throws SQLException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (CollUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
//不允许做全表删除
|
//不允许做全表删除
|
||||||
throw new SQLException("Empty entity provided!");
|
throw new SQLException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
@ -153,10 +153,10 @@ public class DialectRunner implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public int update(Connection conn, Entity record, Entity where) throws SQLException {
|
public int update(Connection conn, Entity record, Entity where) throws SQLException {
|
||||||
checkConn(conn);
|
checkConn(conn);
|
||||||
if (CollUtil.isEmpty(record)) {
|
if (MapUtil.isEmpty(record)) {
|
||||||
throw new SQLException("Empty entity provided!");
|
throw new SQLException("Empty entity provided!");
|
||||||
}
|
}
|
||||||
if (CollUtil.isEmpty(where)) {
|
if (MapUtil.isEmpty(where)) {
|
||||||
//不允许做全表更新
|
//不允许做全表更新
|
||||||
throw new SQLException("Empty where provided!");
|
throw new SQLException("Empty where provided!");
|
||||||
}
|
}
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
package cn.hutool.db;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import cn.hutool.db.dialect.Dialect;
|
|
||||||
import cn.hutool.db.dialect.DialectFactory;
|
|
||||||
import cn.hutool.db.ds.DSFactory;
|
|
||||||
import cn.hutool.db.sql.Wrapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL执行类<br>
|
|
||||||
* 通过给定的数据源执行给定SQL或者给定数据源和方言,执行相应的CRUD操作<br>
|
|
||||||
* SqlRunner中每一个方法都会打开和关闭一个链接<br>
|
|
||||||
* 此类为线程安全的对象,可以单例使用
|
|
||||||
*
|
|
||||||
* @author Luxiaolei
|
|
||||||
* @deprecated 请使用{@link Db}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SqlRunner extends AbstractDb{
|
|
||||||
private static final long serialVersionUID = 6626183393926198184L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SqlRunner<br>
|
|
||||||
* 使用默认数据源,自动探测数据库连接池
|
|
||||||
* @return SqlRunner
|
|
||||||
* @since 3.0.6
|
|
||||||
*/
|
|
||||||
public static SqlRunner create() {
|
|
||||||
return create(DSFactory.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SqlRunner<br>
|
|
||||||
* 使用默认数据源,自动探测数据库连接池
|
|
||||||
*
|
|
||||||
* @param group 数据源分组
|
|
||||||
* @return SqlRunner
|
|
||||||
* @since 4.0.11
|
|
||||||
*/
|
|
||||||
public static SqlRunner create(String group) {
|
|
||||||
return create(DSFactory.get(group));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SqlRunner<br>
|
|
||||||
* 会根据数据源连接的元信息识别目标数据库类型,进而使用合适的数据源
|
|
||||||
* @param ds 数据源
|
|
||||||
* @return SqlRunner
|
|
||||||
*/
|
|
||||||
public static SqlRunner create(DataSource ds) {
|
|
||||||
return ds == null ? null : new SqlRunner(ds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SqlRunner
|
|
||||||
* @param ds 数据源
|
|
||||||
* @param dialect 方言
|
|
||||||
* @return SqlRunner
|
|
||||||
*/
|
|
||||||
public static SqlRunner create(DataSource ds, Dialect dialect) {
|
|
||||||
return new SqlRunner(ds, dialect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建SqlRunner
|
|
||||||
* @param ds 数据源
|
|
||||||
* @param driverClassName 数据库连接驱动类名
|
|
||||||
* @return SqlRunner
|
|
||||||
*/
|
|
||||||
public static SqlRunner create(DataSource ds, String driverClassName) {
|
|
||||||
return new SqlRunner(ds, DialectFactory.newDialect(driverClassName));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------- Constructor start
|
|
||||||
/**
|
|
||||||
* 构造,从DataSource中识别方言
|
|
||||||
* @param ds 数据源
|
|
||||||
*/
|
|
||||||
public SqlRunner(DataSource ds) {
|
|
||||||
this(ds, DialectFactory.getDialect(ds));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造
|
|
||||||
* @param ds 数据源
|
|
||||||
* @param driverClassName 数据库连接驱动类名,用于识别方言
|
|
||||||
*/
|
|
||||||
public SqlRunner(DataSource ds, String driverClassName) {
|
|
||||||
this(ds, DialectFactory.newDialect(driverClassName));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造
|
|
||||||
* @param ds 数据源
|
|
||||||
* @param dialect 方言
|
|
||||||
*/
|
|
||||||
public SqlRunner(DataSource ds, Dialect dialect) {
|
|
||||||
super(ds, dialect);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------- Constructor end
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------- Getters and Setters start
|
|
||||||
@Override
|
|
||||||
public SqlRunner setWrapper(Character wrapperChar) {
|
|
||||||
return (SqlRunner) super.setWrapper(wrapperChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SqlRunner setWrapper(Wrapper wrapper) {
|
|
||||||
return (SqlRunner) super.setWrapper(wrapper);
|
|
||||||
}
|
|
||||||
//---------------------------------------------------------------------------- Getters and Setters end
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection getConnection() throws SQLException{
|
|
||||||
return ds.getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeConnection(Connection conn) {
|
|
||||||
DbUtil.close(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------- Private method start
|
|
||||||
//---------------------------------------------------------------------------- Private method end
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
package cn.hutool.db.ds;
|
package cn.hutool.db.ds;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.io.resource.NoResourceException;
|
import cn.hutool.core.io.resource.NoResourceException;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.DbRuntimeException;
|
import cn.hutool.db.DbRuntimeException;
|
||||||
import cn.hutool.db.DbUtil;
|
import cn.hutool.db.DbUtil;
|
||||||
@ -107,7 +107,7 @@ public abstract class AbstractDSFactory extends DSFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Setting config = setting.getSetting(group);
|
final Setting config = setting.getSetting(group);
|
||||||
if (CollectionUtil.isEmpty(config)) {
|
if (MapUtil.isEmpty(config)) {
|
||||||
throw new DbRuntimeException("No config for group: [{}]", group);
|
throw new DbRuntimeException("No config for group: [{}]", group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public abstract class AbstractDSFactory extends DSFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
if (CollectionUtil.isNotEmpty(dsMap)) {
|
if (MapUtil.isNotEmpty(dsMap)) {
|
||||||
Collection<DataSourceWrapper> values = dsMap.values();
|
Collection<DataSourceWrapper> values = dsMap.values();
|
||||||
for (DataSourceWrapper ds : values) {
|
for (DataSourceWrapper ds : values) {
|
||||||
ds.close();
|
ds.close();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.hutool.db.ds.pooled;
|
package cn.hutool.db.ds.pooled;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.DbRuntimeException;
|
import cn.hutool.db.DbRuntimeException;
|
||||||
import cn.hutool.db.dialect.DriverUtil;
|
import cn.hutool.db.dialect.DriverUtil;
|
||||||
@ -47,7 +47,7 @@ public class DbSetting {
|
|||||||
*/
|
*/
|
||||||
public DbConfig getDbConfig(String group) {
|
public DbConfig getDbConfig(String group) {
|
||||||
final Setting config = setting.getSetting(group);
|
final Setting config = setting.getSetting(group);
|
||||||
if (CollectionUtil.isEmpty(config)) {
|
if (MapUtil.isEmpty(config)) {
|
||||||
throw new DbRuntimeException("No Hutool pool config for group: [{}]", group);
|
throw new DbRuntimeException("No Hutool pool config for group: [{}]", group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.hutool.db.ds.simple;
|
package cn.hutool.db.ds.simple;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.DbRuntimeException;
|
import cn.hutool.db.DbRuntimeException;
|
||||||
@ -82,7 +81,7 @@ public class SimpleDataSource extends AbstractDataSource {
|
|||||||
setting = new Setting(DEFAULT_DB_CONFIG_PATH);
|
setting = new Setting(DEFAULT_DB_CONFIG_PATH);
|
||||||
}
|
}
|
||||||
final Setting config = setting.getSetting(group);
|
final Setting config = setting.getSetting(group);
|
||||||
if (CollectionUtil.isEmpty(config)) {
|
if (MapUtil.isEmpty(config)) {
|
||||||
throw new DbRuntimeException("No DataSource config for group: [{}]", group);
|
throw new DbRuntimeException("No DataSource config for group: [{}]", group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.hutool.db.nosql.mongo;
|
package cn.hutool.db.nosql.mongo;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.RuntimeUtil;
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
import cn.hutool.setting.Setting;
|
import cn.hutool.setting.Setting;
|
||||||
@ -111,7 +111,7 @@ public class MongoFactory {
|
|||||||
* 关闭全部连接
|
* 关闭全部连接
|
||||||
*/
|
*/
|
||||||
public static void closeAll() {
|
public static void closeAll() {
|
||||||
if(CollectionUtil.isNotEmpty(DS_MAP)){
|
if(MapUtil.isNotEmpty(DS_MAP)){
|
||||||
for(MongoDS ds : DS_MAP.values()) {
|
for(MongoDS ds : DS_MAP.values()) {
|
||||||
ds.close();
|
ds.close();
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ package cn.hutool.db.sql;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Editor;
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.CharUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.Entity;
|
import cn.hutool.db.Entity;
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class Wrapper {
|
|||||||
|
|
||||||
//对于Oracle这类数据库,表名中包含用户名需要单独拆分包装
|
//对于Oracle这类数据库,表名中包含用户名需要单独拆分包装
|
||||||
if(field.contains(StrUtil.DOT)){
|
if(field.contains(StrUtil.DOT)){
|
||||||
final Collection<String> target = CollUtil.filter(StrUtil.split(field, StrUtil.C_DOT, 2), (Editor<String>) t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
|
final Collection<String> target = CollUtil.edit(StrUtil.split(field, CharUtil.DOT, 2), t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
|
||||||
return CollectionUtil.join(target, StrUtil.DOT);
|
return CollectionUtil.join(target, StrUtil.DOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@ public class SqlBuilderTest {
|
|||||||
SqlBuilder builder2 = SqlBuilder.create().select().from("user").where(new Condition("name", "is null"));
|
SqlBuilder builder2 = SqlBuilder.create().select().from("user").where(new Condition("name", "is null"));
|
||||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
|
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
|
||||||
|
|
||||||
SqlBuilder builder3 = SqlBuilder.create().select().from("user").where(LogicalOperator.AND, new Condition("name", "!= null"));
|
SqlBuilder builder3 = SqlBuilder.create().select().from("user").where(new Condition("name", "!= null"));
|
||||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
|
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
|
||||||
|
|
||||||
SqlBuilder builder4 = SqlBuilder.create().select().from("user").where(LogicalOperator.AND, new Condition("name", "is not null"));
|
SqlBuilder builder4 = SqlBuilder.create().select().from("user").where(new Condition("name", "is not null"));
|
||||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
|
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package cn.hutool.extra.pinyin;
|
package cn.hutool.extra.pinyin;
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拼音引擎接口,具体的拼音实现通过实现此接口,完成具体实现功能
|
* 拼音引擎接口,具体的拼音实现通过实现此接口,完成具体实现功能
|
||||||
*
|
*
|
||||||
@ -47,7 +49,7 @@ public interface PinyinEngine {
|
|||||||
*/
|
*/
|
||||||
default String getFirstLetter(String str, String separator) {
|
default String getFirstLetter(String str, String separator) {
|
||||||
final String splitSeparator = StrUtil.isEmpty(separator) ? "#" : separator;
|
final String splitSeparator = StrUtil.isEmpty(separator) ? "#" : separator;
|
||||||
final String[] split = StrUtil.split(getPinyin(str, splitSeparator), splitSeparator);
|
final List<String> split = StrUtil.split(getPinyin(str, splitSeparator), splitSeparator);
|
||||||
return ArrayUtil.join(split, separator, (s)->String.valueOf(s.length() > 0 ? s.charAt(0) : ""));
|
return CollUtil.join(split, separator, (s)->String.valueOf(s.length() > 0 ? s.charAt(0) : StrUtil.EMPTY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,8 @@ public class ServletUtil {
|
|||||||
*/
|
*/
|
||||||
public static void write(HttpServletResponse response, InputStream in, String contentType, String fileName) {
|
public static void write(HttpServletResponse response, InputStream in, String contentType, String fileName) {
|
||||||
final String charset = ObjectUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.UTF_8);
|
final String charset = ObjectUtil.defaultIfNull(response.getCharacterEncoding(), CharsetUtil.UTF_8);
|
||||||
response.setHeader("Content-Disposition", StrUtil.format("attachment;filename={}", URLUtil.encode(fileName, charset)));
|
response.setHeader("Content-Disposition", StrUtil.format("attachment;filename={}",
|
||||||
|
URLUtil.encode(fileName, CharsetUtil.charset(charset))));
|
||||||
response.setContentType(contentType);
|
response.setContentType(contentType);
|
||||||
write(response, in);
|
write(response, in);
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package cn.hutool.extra.template;
|
|
||||||
|
|
||||||
import cn.hutool.core.lang.Dict;
|
|
||||||
import org.beetl.core.Configuration;
|
|
||||||
import org.beetl.core.GroupTemplate;
|
|
||||||
import org.beetl.core.Template;
|
|
||||||
import org.beetl.core.resource.StringTemplateResourceLoader;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BeetlUtil单元测试
|
|
||||||
*
|
|
||||||
* @author looly
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class BeetlUtilTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void renderStrTest() throws IOException {
|
|
||||||
GroupTemplate groupTemplate = BeetlUtil.createGroupTemplate(new StringTemplateResourceLoader(), Configuration.defaultConfiguration());
|
|
||||||
Template template = BeetlUtil.getTemplate(groupTemplate, "hello,${name}");
|
|
||||||
String result = BeetlUtil.render(template, Dict.create().set("name", "hutool"));
|
|
||||||
|
|
||||||
Assert.assertEquals("hello,hutool", result);
|
|
||||||
|
|
||||||
String renderFromStr = BeetlUtil.renderFromStr("hello,${name}", Dict.create().set("name", "hutool"));
|
|
||||||
Assert.assertEquals("hello,hutool", renderFromStr);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,9 @@
|
|||||||
package cn.hutool.http;
|
package cn.hutool.http;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -7,9 +11,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局头部信息<br>
|
* 全局头部信息<br>
|
||||||
* 所有Http请求将共用此全局头部信息,除非在{@link HttpRequest}中自定义头部信息覆盖之
|
* 所有Http请求将共用此全局头部信息,除非在{@link HttpRequest}中自定义头部信息覆盖之
|
||||||
@ -165,7 +166,7 @@ public enum GlobalHeaders {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public GlobalHeaders header(Map<String, List<String>> headers) {
|
public GlobalHeaders header(Map<String, List<String>> headers) {
|
||||||
if (CollectionUtil.isEmpty(headers)) {
|
if (MapUtil.isEmpty(headers)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package cn.hutool.http;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ public abstract class HttpBase<T> {
|
|||||||
* @since 4.6.3
|
* @since 4.6.3
|
||||||
*/
|
*/
|
||||||
public T headerMap(Map<String, String> headers, boolean isOverride) {
|
public T headerMap(Map<String, String> headers, boolean isOverride) {
|
||||||
if(CollectionUtil.isEmpty(headers)) {
|
if(MapUtil.isEmpty(headers)) {
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ public abstract class HttpBase<T> {
|
|||||||
* @since 4.0.8
|
* @since 4.0.8
|
||||||
*/
|
*/
|
||||||
public T header(Map<String, List<String>> headers, boolean isOverride) {
|
public T header(Map<String, List<String>> headers, boolean isOverride) {
|
||||||
if(CollectionUtil.isEmpty(headers)) {
|
if(MapUtil.isEmpty(headers)) {
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ public abstract class HttpBase<T> {
|
|||||||
* @since 4.0.3
|
* @since 4.0.3
|
||||||
*/
|
*/
|
||||||
public T addHeaders(Map<String, String> headers) {
|
public T addHeaders(Map<String, String> headers) {
|
||||||
if(CollectionUtil.isEmpty(headers)) {
|
if(MapUtil.isEmpty(headers)) {
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class JSONUtilTest {
|
|||||||
a2.setName("AAAA222Name");
|
a2.setName("AAAA222Name");
|
||||||
|
|
||||||
ArrayList<UserA> list = CollectionUtil.newArrayList(a1, a2);
|
ArrayList<UserA> list = CollectionUtil.newArrayList(a1, a2);
|
||||||
HashMap<String, Object> map = CollectionUtil.newHashMap();
|
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||||
map.put("total", 13);
|
map.put("total", 13);
|
||||||
map.put("rows", list);
|
map.put("rows", list);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public class TransientTest {
|
|||||||
detailBill.setBizNo("bizNo");
|
detailBill.setBizNo("bizNo");
|
||||||
|
|
||||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||||
JSONConfig.create().setIgnoreTransient(true));
|
JSONConfig.create().setTransientSupport(false));
|
||||||
Assert.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
Assert.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package cn.hutool.setting;
|
package cn.hutool.setting;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.bean.copier.ValueProvider;
|
import cn.hutool.core.bean.copier.ValueProvider;
|
||||||
@ -14,6 +11,9 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setting抽象类
|
* Setting抽象类
|
||||||
*
|
*
|
||||||
@ -156,7 +156,7 @@ public abstract class AbsSetting implements OptNullBasicTypeFromStringGetter<Str
|
|||||||
if (StrUtil.isBlank(value)) {
|
if (StrUtil.isBlank(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return StrUtil.split(value, delimiter);
|
return StrUtil.splitToArray(value, delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------- Get int
|
// --------------------------------------------------------------- Get int
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package cn.hutool.setting.dialect;
|
package cn.hutool.setting.dialect;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.getter.BasicTypeGetter;
|
import cn.hutool.core.getter.BasicTypeGetter;
|
||||||
import cn.hutool.core.getter.OptBasicTypeGetter;
|
import cn.hutool.core.getter.OptBasicTypeGetter;
|
||||||
@ -17,6 +16,7 @@ import cn.hutool.core.io.watch.SimpleWatcher;
|
|||||||
import cn.hutool.core.io.watch.WatchMonitor;
|
import cn.hutool.core.io.watch.WatchMonitor;
|
||||||
import cn.hutool.core.io.watch.WatchUtil;
|
import cn.hutool.core.io.watch.WatchUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@ -246,7 +246,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
|||||||
* @param properties 属性文件路径
|
* @param properties 属性文件路径
|
||||||
*/
|
*/
|
||||||
public Props(Properties properties) {
|
public Props(Properties properties) {
|
||||||
if (CollectionUtil.isNotEmpty(properties)) {
|
if (MapUtil.isNotEmpty(properties)) {
|
||||||
this.putAll(properties);
|
this.putAll(properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ public class SettingTest {
|
|||||||
public void settingTestForCustom() {
|
public void settingTestForCustom() {
|
||||||
Setting setting = new Setting();
|
Setting setting = new Setting();
|
||||||
|
|
||||||
setting.put("group1", "user", "root");
|
setting.setByGroup("user", "group1", "root");
|
||||||
setting.put("group2", "user", "root2");
|
setting.setByGroup("user", "group2", "root2");
|
||||||
setting.put("group3", "user", "root3");
|
setting.setByGroup("user", "group3", "root3");
|
||||||
setting.set("user", "root4");
|
setting.set("user", "root4");
|
||||||
|
|
||||||
Assert.assertEquals("root", setting.getByGroup("user", "group1"));
|
Assert.assertEquals("root", setting.getByGroup("user", "group1"));
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package cn.hutool.system;
|
package cn.hutool.system;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代表当前运行的JRE的信息。
|
* 代表当前运行的JRE的信息。
|
||||||
*/
|
*/
|
||||||
@ -138,7 +138,7 @@ public class JavaRuntimeInfo implements Serializable{
|
|||||||
* @since Java 1.1
|
* @since Java 1.1
|
||||||
*/
|
*/
|
||||||
public final String[] getClassPathArray() {
|
public final String[] getClassPathArray() {
|
||||||
return StrUtil.split(getClassPath(), SystemUtil.get("path.separator", false));
|
return StrUtil.splitToArray(getClassPath(), SystemUtil.get("path.separator", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +182,7 @@ public class JavaRuntimeInfo implements Serializable{
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final String[] getLibraryPathArray() {
|
public final String[] getLibraryPathArray() {
|
||||||
return StrUtil.split(getLibraryPath(), SystemUtil.get("path.separator", false));
|
return StrUtil.splitToArray(getLibraryPath(), SystemUtil.get("path.separator", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user