This commit is contained in:
Looly 2021-02-26 23:18:05 +08:00
parent 32c4952d31
commit e3c1852c4d
3 changed files with 35 additions and 23 deletions

View File

@ -473,8 +473,9 @@ public class Condition extends CloneSupport<Condition> {
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<Condition> {
*/
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){

View File

@ -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());
}
}

View File

@ -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);
}