From e3c1852c4d2c83c52a40c8994da868a0981ae733 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 26 Feb 2021 23:18:05 +0800 Subject: [PATCH] fix code --- .../main/java/cn/hutool/db/sql/Condition.java | 8 +++- .../java/cn/hutool/db/sql/ConditionTest.java | 6 +++ .../main/java/cn/hutool/extra/ftp/Ftp.java | 44 ++++++++++--------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/hutool-db/src/main/java/cn/hutool/db/sql/Condition.java b/hutool-db/src/main/java/cn/hutool/db/sql/Condition.java index 8cea8d6c9..e5ecb0fc7 100644 --- a/hutool-db/src/main/java/cn/hutool/db/sql/Condition.java +++ b/hutool-db/src/main/java/cn/hutool/db/sql/Condition.java @@ -473,8 +473,9 @@ public class Condition extends CloneSupport { final String firstPart = strs.get(0).trim().toUpperCase(); if (OPERATORS.contains(firstPart)) { this.operator = firstPart; - // 比较符号后跟大部分为数字,此处做转换 - this.value = tryToNumber(strs.get(1)); + // 比较符号后跟大部分为数字,此处做转换(IN不做转换) + final String valuePart = strs.get(1); + this.value = isOperatorIn() ? valuePart : tryToNumber(valuePart); return; } @@ -537,6 +538,9 @@ public class Condition extends CloneSupport { */ private static Object tryToNumber(String value){ value = StrUtil.trim(value); + if(false == NumberUtil.isNumber(value)){ + return value; + } try{ return NumberUtil.parseNumber(value); } catch (Exception ignore){ diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java index c3078485d..13bbc6b05 100644 --- a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java @@ -60,4 +60,10 @@ public class ConditionTest { // issue I38LTM Assert.assertSame(Long.class, age.getValue().getClass()); } + + @Test + public void parseInTest(){ + final Condition age = Condition.parse("age", "in 1,2,3"); + Assert.assertEquals("age IN (?,?,?)", age.toString()); + } } diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java index 60f8e99b1..1f49f2ebd 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java @@ -105,12 +105,14 @@ public class Ftp extends AbstractFtp { /** * 构造 * - * @param host 域名或IP - * @param port 端口 - * @param user 用户名 - * @param password 密码 - * @param charset 编码 - * @param mode 模式 + * @param host 域名或IP + * @param port 端口 + * @param user 用户名 + * @param password 密码 + * @param charset 编码 + * @param serverLanguageCode 服务器语言 + * @param systemKey 系统关键字 + * @param mode 模式 */ public Ftp(String host, int port, String user, String password, Charset charset, String serverLanguageCode, String systemKey, FtpMode mode) { this(new FtpConfig(host, port, user, password, charset, serverLanguageCode, systemKey), mode); @@ -338,14 +340,14 @@ public class Ftp extends AbstractFtp { * * @param path 目录,如果目录不存在,抛出异常 * @return 文件或目录列表 - * @throws FtpException 路径不存在 + * @throws FtpException 路径不存在 * @throws IORuntimeException IO异常 */ - public FTPFile[] lsFiles(String path) throws FtpException, IORuntimeException{ + public FTPFile[] lsFiles(String path) throws FtpException, IORuntimeException { String pwd = null; if (StrUtil.isNotBlank(path)) { pwd = pwd(); - if(false == cd(path)){ + if (false == cd(path)) { throw new FtpException("Change dir to [{}] error, maybe path not exist!", path); } } @@ -364,7 +366,7 @@ public class Ftp extends AbstractFtp { } @Override - public boolean mkdir(String dir) throws IORuntimeException{ + public boolean mkdir(String dir) throws IORuntimeException { try { return this.client.makeDirectory(dir); } catch (IOException e) { @@ -379,7 +381,7 @@ public class Ftp extends AbstractFtp { * @return 状态int,服务端不同,返回不同 * @since 5.4.3 */ - public int stat(String path) throws IORuntimeException{ + public int stat(String path) throws IORuntimeException { try { return this.client.stat(path); } catch (IOException e) { @@ -394,7 +396,7 @@ public class Ftp extends AbstractFtp { * @return 是否存在 * @throws IORuntimeException IO异常 */ - public boolean existFile(String path) throws IORuntimeException{ + public boolean existFile(String path) throws IORuntimeException { FTPFile[] ftpFileArr; try { ftpFileArr = client.listFiles(path); @@ -405,11 +407,11 @@ public class Ftp extends AbstractFtp { } @Override - public boolean delFile(String path) throws IORuntimeException{ + public boolean delFile(String path) throws IORuntimeException { final String pwd = pwd(); final String fileName = FileUtil.getName(path); final String dir = StrUtil.removeSuffix(path, fileName); - if(false == cd(dir)){ + if (false == cd(dir)) { throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path); } @@ -426,7 +428,7 @@ public class Ftp extends AbstractFtp { } @Override - public boolean delDir(String dirPath) throws IORuntimeException{ + public boolean delDir(String dirPath) throws IORuntimeException { FTPFile[] dirs; try { dirs = client.listFiles(dirPath); @@ -490,7 +492,7 @@ public class Ftp extends AbstractFtp { * @return 是否上传成功 * @throws IORuntimeException IO异常 */ - public boolean upload(String path, String fileName, File file) throws IORuntimeException{ + public boolean upload(String path, String fileName, File file) throws IORuntimeException { try (InputStream in = FileUtil.getInputStream(file)) { return upload(path, fileName, in); } catch (IOException e) { @@ -513,7 +515,7 @@ public class Ftp extends AbstractFtp { * @return 是否上传成功 * @throws IORuntimeException IO异常 */ - public boolean upload(String path, String fileName, InputStream fileStream) throws IORuntimeException{ + public boolean upload(String path, String fileName, InputStream fileStream) throws IORuntimeException { try { client.setFileType(FTPClient.BINARY_FILE_TYPE); } catch (IOException e) { @@ -594,7 +596,7 @@ public class Ftp extends AbstractFtp { * @param outFile 输出文件或目录 * @throws IORuntimeException IO异常 */ - public void download(String path, String fileName, File outFile) throws IORuntimeException{ + public void download(String path, String fileName, File outFile) throws IORuntimeException { if (outFile.isDirectory()) { outFile = new File(outFile, fileName); } @@ -626,16 +628,16 @@ public class Ftp extends AbstractFtp { * @param fileName 文件名 * @param out 输出位置 * @param fileNameCharset 文件名编码 - * @since 5.5.7 * @throws IORuntimeException IO异常 + * @since 5.5.7 */ - public void download(String path, String fileName, OutputStream out, Charset fileNameCharset) throws IORuntimeException{ + public void download(String path, String fileName, OutputStream out, Charset fileNameCharset) throws IORuntimeException { String pwd = null; if (this.backToPwd) { pwd = pwd(); } - if(false == cd(path)){ + if (false == cd(path)) { throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path); }