【同步】BOOT 和 CLOUD 的功能

This commit is contained in:
YunaiV
2025-12-07 18:20:05 +08:00
parent af5bb360bf
commit b5a7350fe9
10 changed files with 248 additions and 155 deletions

View File

@@ -27,10 +27,10 @@ public class PageParam implements Serializable {
@Min(value = 1, message = "页码最小值为 1")
private Integer pageNo = PAGE_NO;
@Schema(description = "每页条数,最大值为 100", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@Schema(description = "每页条数,最大值为 200", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@NotNull(message = "每页条数不能为空")
@Min(value = 1, message = "每页条数最小值为 1")
@Max(value = 100, message = "每页条数最大值为 100")
@Max(value = 200, message = "每页条数最大值为 200")
private Integer pageSize = PAGE_SIZE;
}

View File

@@ -13,6 +13,7 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -35,6 +36,16 @@ public class HttpUtils {
return URLEncoder.encode(value, StandardCharsets.UTF_8);
}
/**
* 解码 URL 参数
*
* @param value 参数
* @return 解码后的参数
*/
public static String decodeUtf8(String value) {
return URLDecoder.decode(value, StandardCharsets.UTF_8);
}
@SuppressWarnings("unchecked")
public static String replaceUrlQuery(String url, String key, String value) {
UrlBuilder builder = UrlBuilder.of(url, Charset.defaultCharset());

View File

@@ -23,16 +23,18 @@ public class TimestampLocalDateTimeSerializer extends JsonSerializer<LocalDateTi
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
String fieldName = gen.getOutputContext().getCurrentName();
Class<?> clazz = gen.getOutputContext().getCurrentValue().getClass();
Field field = ReflectUtil.getField(clazz, fieldName);
// 情况一:有 JsonFormat 自定义注解则使用它。https://github.com/YunaiV/ruoyi-vue-pro/pull/1019
JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class);
if (jsonFormats.length > 0) {
String pattern = jsonFormats[0].pattern();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
gen.writeString(formatter.format(value));
return;
String fieldName = gen.getOutputContext().getCurrentName();
if (fieldName != null) {
Class<?> clazz = gen.getOutputContext().getCurrentValue().getClass();
Field field = ReflectUtil.getField(clazz, fieldName);
JsonFormat[] jsonFormats = field.getAnnotationsByType(JsonFormat.class);
if (jsonFormats.length > 0) {
String pattern = jsonFormats[0].pattern();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
gen.writeString(formatter.format(value));
return;
}
}
// 情况二:默认将 LocalDateTime 对象,转换为 Long 时间戳