Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
qaiu committed Nov 7, 2024
1 parent a01df6c commit b6a9c2d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 264 deletions.
6 changes: 0 additions & 6 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
19 changes: 0 additions & 19 deletions core/src/main/java/cn/qaiu/vx/core/util/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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;

Expand Down Expand Up @@ -99,23 +97,6 @@ public static JsonObject getSubJsonForEntity(JsonObject jsonObject, Class<?> cla
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);
}
}

/**
* 处理其他配置
*
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
Original file line number Diff line number Diff line change
@@ -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() {}

}
25 changes: 8 additions & 17 deletions core/src/main/java/cn/qaiu/vx/core/util/ParamUtil.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,29 +17,21 @@
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand Down
13 changes: 11 additions & 2 deletions web-front/src/components/DarkMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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>
1 change: 1 addition & 0 deletions web-service/src/main/java/cn/qaiu/lz/AppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static void main(String[] args) {
}

/**
* 框架回调方法
* 初始化数据库/缓存等
*
* @param jsonObject 配置
Expand Down
12 changes: 12 additions & 0 deletions web-service/src/main/java/cn/qaiu/lz/web/model/SysUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

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
Expand All @@ -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"));
}
}
}
2 changes: 1 addition & 1 deletion web-service/src/main/resources/http-tools/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
Loading

0 comments on commit b6a9c2d

Please sign in to comment.