mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 04:13:03 +00:00
.
This commit is contained in:
@@ -60,12 +60,6 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.melloware/commons-beanutils2 -->
|
||||
<dependency>
|
||||
<groupId>com.melloware</groupId>
|
||||
<artifactId>commons-beanutils2</artifactId>
|
||||
<version>${commons-beanutils2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
||||
@@ -3,8 +3,6 @@ package cn.qaiu.vx.core.util;
|
||||
import cn.qaiu.vx.core.annotaions.HandleSortFilter;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.apache.commons.beanutils2.ConvertUtils;
|
||||
import org.apache.commons.beanutils2.Converter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -99,23 +97,6 @@ public class CommonUtil {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册枚举转换器
|
||||
*
|
||||
* @param enums 枚举类
|
||||
*/
|
||||
@SafeVarargs
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static void enumConvert(Class<? extends Enum>... enums) {
|
||||
for (Class<? extends Enum> anEnum : enums) {
|
||||
ConvertUtils.register(new Converter() {
|
||||
public Object convert(Class type, Object value) {
|
||||
return Enum.valueOf(anEnum, (String) value);
|
||||
}
|
||||
}, anEnum);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理其他配置
|
||||
*
|
||||
|
||||
46
core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
Normal file
46
core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import io.vertx.core.json.jackson.DatabindCodec;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @date 2023/10/14 9:07
|
||||
*/
|
||||
public class JacksonConfig {
|
||||
|
||||
static {
|
||||
// 通过该方法对mapper对象进行设置,所有序列化的对象都将按改规则进行系列化
|
||||
// Include.Include.ALWAYS 默认
|
||||
// Include.NON_DEFAULT 属性为默认值不序列化
|
||||
// Include.NON_EMPTY 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量
|
||||
// Include.NON_NULL 属性为NULL 不序列化,就是为null的字段不参加序列化
|
||||
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
ObjectMapper objectMapper = DatabindCodec.mapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class,
|
||||
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
javaTimeModule.addDeserializer(LocalDate.class,
|
||||
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
javaTimeModule.addDeserializer(LocalTime.class,
|
||||
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
LoggerFactory.getLogger(JacksonConfig.class).info("Global JacksonConfig complete.");
|
||||
}
|
||||
|
||||
public static void nothing() {}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import io.vertx.core.MultiMap;
|
||||
import org.apache.commons.beanutils2.BeanUtils;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -18,29 +17,21 @@ import java.util.Map;
|
||||
public final class ParamUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ParamUtil.class);
|
||||
|
||||
public static Map<String, String> multiMapToMap(MultiMap multiMap) {
|
||||
public static Map<String, Object> multiMapToMap(MultiMap multiMap) {
|
||||
if (multiMap == null) return null;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : multiMap.entries()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <T> T multiMapToEntity(MultiMap multiMap, Class<T> tClass) throws NoSuchMethodException {
|
||||
Map<String, String> map = multiMapToMap(multiMap);
|
||||
T obj = null;
|
||||
try {
|
||||
obj = tClass.getDeclaredConstructor().newInstance();
|
||||
BeanUtils.populate(obj, map);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("实例化异常");
|
||||
} catch (InvocationTargetException e2) {
|
||||
e2.printStackTrace();
|
||||
LOGGER.error("map2bean转换异常");
|
||||
public static <T> T multiMapToEntity(MultiMap multiMap, Class<T> tClass) {
|
||||
Map<String, Object> map = multiMapToMap(multiMap);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return obj;
|
||||
return new JsonObject(map).mapTo(tClass);
|
||||
}
|
||||
|
||||
public static MultiMap paramsToMap(String paramString) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.qaiu.vx.core.verticle;
|
||||
|
||||
import cn.qaiu.vx.core.handlerfactory.RouterHandlerFactory;
|
||||
import cn.qaiu.vx.core.util.CommonUtil;
|
||||
import cn.qaiu.vx.core.util.JacksonConfig;
|
||||
import cn.qaiu.vx.core.util.SharedDataUtil;
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Promise;
|
||||
@@ -30,6 +31,8 @@ public class RouterVerticle extends AbstractVerticle {
|
||||
private HttpServer server;
|
||||
|
||||
static {
|
||||
LOGGER.info(JacksonConfig.class.getSimpleName() + " >> ");
|
||||
JacksonConfig.nothing();
|
||||
LOGGER.info("To start listening to port {} ......", port);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref,watch } from 'vue'
|
||||
import { useDark, useToggle } from '@vueuse/core'
|
||||
/** 引入Element-Plus图标 */
|
||||
import { Sunny, Moon } from '@element-plus/icons-vue'
|
||||
@@ -23,6 +23,15 @@ defineOptions({
|
||||
const isDark = useDark({})
|
||||
|
||||
const toggleDark = useToggle(isDark)
|
||||
|
||||
let item = window.localStorage.getItem("darkMode");
|
||||
if (item) {
|
||||
item = (item === 'true');
|
||||
}
|
||||
/** 是否切换为暗黑模式 */
|
||||
const darkMode = ref(false)
|
||||
const darkMode = ref(item)
|
||||
watch(darkMode, (newValue) => {
|
||||
console.log(`darkMode: ${newValue}`)
|
||||
window.localStorage.setItem("darkMode", newValue);
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -28,6 +28,7 @@ public class AppMain {
|
||||
}
|
||||
|
||||
/**
|
||||
* 框架回调方法
|
||||
* 初始化数据库/缓存等
|
||||
*
|
||||
* @param jsonObject 配置
|
||||
|
||||
@@ -2,11 +2,15 @@ package cn.qaiu.lz.web.model;
|
||||
|
||||
import cn.qaiu.db.ddl.Table;
|
||||
import cn.qaiu.lz.common.ToJson;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Data
|
||||
@DataObject
|
||||
@NoArgsConstructor
|
||||
@@ -16,9 +20,17 @@ public class SysUser implements ToJson {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
private Integer age;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
public SysUser(JsonObject json) {
|
||||
this.id = json.getString("id");
|
||||
this.username = json.getString("username");
|
||||
this.password = json.getString("password");
|
||||
this.age = json.getInteger("age");
|
||||
if (json.getString("createTime") != null) {
|
||||
this.createTime = LocalDateTime.parse(json.getString("createTime"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ GET http://127.0.0.1:6400/v2/linkInfo?url=https://www.123865.com/s/iaKtVv-6OECd.
|
||||
GET http://127.0.0.1:6400/v2/linkInfo?url=https://pan.seeoss.com/s/nLNsQ&pwd=DcGe
|
||||
|
||||
###
|
||||
POST http://127.0.0.1:6400/v2/login?username=asd
|
||||
POST http://127.0.0.1:6400/v2/login?username=asd&age=12&password=123123&createTime=2011-12-03T10:15:30
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
package cn.qaiu.web.test;
|
||||
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import org.apache.commons.beanutils2.BeanUtils;
|
||||
import org.apache.commons.beanutils2.ConvertUtils;
|
||||
import org.apache.commons.beanutils2.Converter;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <br>Create date 2021/4/29 15:27
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class Test01 {
|
||||
|
||||
public static class A {
|
||||
String name;
|
||||
String num;
|
||||
String num2;
|
||||
String num3;
|
||||
|
||||
Integer num5;
|
||||
public Integer getNum5() {
|
||||
return num5;
|
||||
}
|
||||
|
||||
public void setNum5(Integer num5) {
|
||||
this.num5 = num5;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(String num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public String getNum2() {
|
||||
return num2;
|
||||
}
|
||||
|
||||
public void setNum2(String num2) {
|
||||
this.num2 = num2;
|
||||
}
|
||||
|
||||
public String getNum3() {
|
||||
return num3;
|
||||
}
|
||||
|
||||
public void setNum3(String num3) {
|
||||
this.num3 = num3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class B0{
|
||||
int num;
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(int num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class B extends B0{
|
||||
String name;
|
||||
|
||||
boolean flag;
|
||||
int num4;
|
||||
Date date;
|
||||
String dateStr;
|
||||
|
||||
Integer num5;
|
||||
|
||||
public Boolean getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(Boolean flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public Integer getNum5() {
|
||||
return num5;
|
||||
}
|
||||
|
||||
public void setNum5(Integer num5) {
|
||||
this.num5 = num5;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getDateStr() {
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
public void setDateStr(String dateStr) {
|
||||
this.dateStr = dateStr;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getNum4() {
|
||||
return num4;
|
||||
}
|
||||
|
||||
public void setNum4(int num4) {
|
||||
this.num4 = num4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B{" +
|
||||
"num=" + num +
|
||||
", name='" + name + '\'' +
|
||||
", flag=" + flag +
|
||||
", num4=" + num4 +
|
||||
", date=" + date +
|
||||
", dateStr='" + dateStr + '\'' +
|
||||
", num5=" + num5 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getParamsToBean(RoutingContext ctx, Class<T> tClass) {
|
||||
// ObjectUtils.identityToString()
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
|
||||
A a = new A();
|
||||
a.setName("asd");
|
||||
a.setNum("123");
|
||||
a.setNum2("123");
|
||||
a.setNum3("123");
|
||||
a.setNum5(9999);
|
||||
B b = new B();
|
||||
BeanUtils.copyProperties(b, a);
|
||||
System.out.println(b);
|
||||
a.setNum5(233);
|
||||
System.out.println(b);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "小米");
|
||||
map.put("flag", "1");
|
||||
map.put("num", "553454344");
|
||||
map.put("num2", "123");
|
||||
map.put("num4", "q");
|
||||
map.put("dateStr", new Date());
|
||||
map.put("date", "2021-01-01");
|
||||
B b1 = new B();
|
||||
|
||||
ConvertUtils.register(
|
||||
new Converter() {
|
||||
@Override
|
||||
public <T> T convert(Class<T> clazz, Object value) {
|
||||
//字符串转换为日期
|
||||
try {
|
||||
return (T) DateUtils.parseDate(value.toString(), "yyyy-MM-dd");
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, Date.class);
|
||||
|
||||
|
||||
ConvertUtils.register(
|
||||
new Converter() {
|
||||
@Override
|
||||
public <T> T convert(Class<T> clazz, Object value) {
|
||||
//日期->字符串
|
||||
try {
|
||||
return (T) DateFormatUtils.format((Date) value, "yyyy-MM-dd");
|
||||
}catch (Exception e){
|
||||
return (T)value;
|
||||
}
|
||||
}
|
||||
}, String.class);
|
||||
|
||||
BeanUtils.populate(b1, map);
|
||||
System.out.println(b1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user