6 Commits
main ... v2.8.1

Author SHA1 Message Date
redkale
fbc4436c7c Copier重载copy方法 2025-04-08 12:10:18 +08:00
redkale
3d847fb9b7 格式化 2025-03-15 11:51:02 +08:00
redkale
bdcebcb67d 修复cache.updateColumn方法没有识别ColumnXXXNode问题 2025-01-06 19:24:06 +08:00
redkale
e85e8b745f 增加nowDay方法 2025-01-06 18:57:38 +08:00
redkale
be13d9711f RetResult增加cast方法 2025-01-02 18:25:58 +08:00
redkale
76c4a36ec7 Redkale 2.8.1 开始 2025-01-02 18:18:22 +08:00
9 changed files with 72 additions and 14 deletions

View File

@@ -8,7 +8,7 @@
<name>RedkaleProject</name> <name>RedkaleProject</name>
<url>https://redkale.org</url> <url>https://redkale.org</url>
<description>redkale -- java framework</description> <description>redkale -- java framework</description>
<version>2.8.0-SNAPSHOT</version> <version>2.8.1-SNAPSHOT</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@@ -31,6 +31,13 @@ public interface ApplicationListener {
*/ */
default void onPreStart(Application application) {} default void onPreStart(Application application) {}
/**
* Application在运行start后调用
*
* @param application Application
*/
default void onPostStart(Application application) {}
/** /**
* 服务全部停掉前被调用 * 服务全部停掉前被调用
* *
@@ -45,13 +52,6 @@ public interface ApplicationListener {
*/ */
default void onServersPostStop(Application application) {} default void onServersPostStop(Application application) {}
/**
* Application在运行start后调用
*
* @param application Application
*/
default void onPostStart(Application application) {}
/** /**
* Application在运行Compile前调用 * Application在运行Compile前调用
* *

View File

@@ -58,7 +58,12 @@ public class JsonObject extends LinkedHashMap<String, Object> implements JsonEle
return convertFrom(JsonConvert.root().convertTo(bean)); return convertFrom(JsonConvert.root().convertTo(bean));
} }
@Deprecated(since = "2.8.1")
public <T> T toObject(Type type) { public <T> T toObject(Type type) {
return cast(type);
}
public <T> T cast(Type type) {
return (T) JsonConvert.root().convertFrom(type, JsonConvert.root().convertTo(this)); return (T) JsonConvert.root().convertFrom(type, JsonConvert.root().convertTo(this));
} }

View File

@@ -5,10 +5,9 @@
*/ */
package org.redkale.net.http; package org.redkale.net.http;
import static java.nio.file.StandardWatchEventKinds.*;
import java.io.*; import java.io.*;
import java.nio.file.*; import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
import java.util.*; import java.util.*;
import java.util.AbstractMap.SimpleEntry; import java.util.AbstractMap.SimpleEntry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -52,7 +51,7 @@ public class HttpResourceServlet extends HttpServlet {
key.cancel(); key.cancel();
continue; continue;
} }
key.pollEvents().stream().forEach((event) -> { key.pollEvents().forEach(event -> {
try { try {
Path path = parent.resolve((Path) event.context()); Path path = parent.resolve((Path) event.context());
final String uri = final String uri =
@@ -92,10 +91,10 @@ public class HttpResourceServlet extends HttpServlet {
protected final LongAdder cachedLength = new LongAdder(); protected final LongAdder cachedLength = new LongAdder();
// 缓存总大小, 默认0 // 缓存总大小, 默认0
protected long cachelimit = 0 * 1024 * 1024L; protected long cachelimit = 0L * 1024 * 1024L;
// 最大可缓存的文件大小, 大于该值的文件将不被缓存 // 最大可缓存的文件大小, 大于该值的文件将不被缓存
protected long cachelengthmax = 1 * 1024 * 1024; protected long cachelengthmax = 1L * 1024 * 1024;
// 是否监控缓存文件的变化, 默认不监控 // 是否监控缓存文件的变化, 默认不监控
protected boolean watch = false; protected boolean watch = false;

View File

@@ -97,6 +97,22 @@ public class RetResult<T> implements Serializable {
return this; return this;
} }
public <V> RetResult<V> cast(Type newType) {
return cast(this, newType);
}
public static <V> RetResult<V> cast(RetResult rs, Type newType) {
Object d = rs.result;
if (d != null) {
String text = d instanceof CharSequence
? d.toString()
: JsonConvert.root().convertTo(d);
V n = JsonConvert.root().convertFrom(newType, text);
return new RetResult(rs.retcode, rs.retinfo, n).convert(rs.convert);
}
return rs;
}
public CompletableFuture<RetResult<T>> toFuture() { public CompletableFuture<RetResult<T>> toFuture() {
return CompletableFuture.completedFuture(this); return CompletableFuture.completedFuture(this);
} }

View File

@@ -1084,6 +1084,12 @@ public final class EntityCache<T> {
case SET: case SET:
if (val instanceof ColumnExpNode) { if (val instanceof ColumnExpNode) {
val = updateColumnExpNode(attr, entity, (ColumnExpNode) val); val = updateColumnExpNode(attr, entity, (ColumnExpNode) val);
} else if (val instanceof ColumnNameNode) {
val = ((ColumnNameNode) val).getColumn();
} else if (val instanceof ColumnStringNode) {
val = ((ColumnStringNode) val).getValue();
} else if (val instanceof ColumnNumberNode) {
val = ((ColumnNumberNode) val).getValue();
} }
newVal = val; newVal = val;
if (val instanceof Number) { if (val instanceof Number) {

View File

@@ -81,6 +81,17 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
.apply(src, dest); .apply(src, dest);
} }
/**
* 将源对象复制一份
*
* @param <S> 源类泛型
* @param src 源对象
* @return 目标对象
*/
public static <S> S copy(final S src) {
return src == null ? null : (S) copy(src, src.getClass());
}
/** /**
* 将源对象字段复制到目标对象 * 将源对象字段复制到目标对象
* *

View File

@@ -23,7 +23,7 @@ public final class Redkale {
} }
public static String getDotedVersion() { public static String getDotedVersion() {
return "2.8.0"; return "2.8.1";
} }
public static int getMajorVersion() { public static int getMajorVersion() {

View File

@@ -21,6 +21,8 @@ public final class Times {
private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset(); private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset();
static final String FORMAT_DAY = "%1$tY-%1$tm-%1$td"; // yyyy-MM-dd
static final String FORMAT_SECONDS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"; // yyyy-MM-dd HH:mm:ss static final String FORMAT_SECONDS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"; // yyyy-MM-dd HH:mm:ss
static final String FORMAT_MILLS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL"; // yyyy-MM-dd HH:mm:ss.fff static final String FORMAT_MILLS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL"; // yyyy-MM-dd HH:mm:ss.fff
@@ -47,6 +49,25 @@ public final class Times {
return String.format(FORMAT_MILLS, System.currentTimeMillis()); return String.format(FORMAT_MILLS, System.currentTimeMillis());
} }
/**
* 获取当天2015-01-01格式的string值
*
* @return 2015-01-01格式的string值
*/
public static String nowDay() {
return String.format(FORMAT_DAY, System.currentTimeMillis());
}
/**
* 将指定时间格式化为 yyyy-MM-dd
*
* @param time 待格式化的时间
* @return 格式为yyyy-MM-dd的时间值
*/
public static String formatDay(long time) {
return String.format(FORMAT_DAY, time);
}
/** /**
* 将指定时间格式化为 yyyy-MM-dd HH:mm:ss * 将指定时间格式化为 yyyy-MM-dd HH:mm:ss
* *