mirror of https://gitee.com/xiaonuobase/snowy
fix:修复使用Gson序列化时,MyBatis自动填充createTime和updateTime不一致的问题
parent
d2c9912724
commit
ac85622227
|
@ -21,7 +21,6 @@ import cn.dev33.satoken.router.SaRouter;
|
|||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
|
@ -81,6 +80,8 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -268,7 +269,8 @@ public class GlobalConfigure implements WebMvcConfigurer {
|
|||
// 如果是预检请求,则立即返回到前端
|
||||
SaRouter.match(SaHttpMethod.OPTIONS)
|
||||
// OPTIONS预检请求,不做处理
|
||||
.free(r -> {})
|
||||
.free(r -> {
|
||||
})
|
||||
.back();
|
||||
})
|
||||
|
||||
|
@ -563,19 +565,29 @@ public class GlobalConfigure implements WebMvcConfigurer {
|
|||
@Component
|
||||
public static class CustomMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
/** 删除标志 */
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
private static final String DELETE_FLAG = "deleteFlag";
|
||||
|
||||
/** 创建人 */
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private static final String CREATE_USER = "createUser";
|
||||
|
||||
/** 创建时间 */
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private static final String CREATE_TIME = "createTime";
|
||||
|
||||
/** 更新人 */
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private static final String UPDATE_USER = "updateUser";
|
||||
|
||||
/** 更新时间 */
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private static final String UPDATE_TIME = "updateTime";
|
||||
|
||||
@Override
|
||||
|
@ -586,21 +598,26 @@ public class GlobalConfigure implements WebMvcConfigurer {
|
|||
if (ObjectUtil.isNull(deleteFlag)) {
|
||||
setFieldValByName(DELETE_FLAG, EnumUtil.toString(CommonDeleteFlagEnum.NOT_DELETE), metaObject);
|
||||
}
|
||||
} catch (ReflectionException ignored) { }
|
||||
} catch (ReflectionException ignored) {
|
||||
}
|
||||
try {
|
||||
//为空则设置createUser
|
||||
Object createUser = metaObject.getValue(CREATE_USER);
|
||||
if (ObjectUtil.isNull(createUser)) {
|
||||
setFieldValByName(CREATE_USER, this.getUserId(), metaObject);
|
||||
}
|
||||
} catch (ReflectionException ignored) { }
|
||||
} catch (ReflectionException ignored) {
|
||||
}
|
||||
try {
|
||||
//为空则设置createTime
|
||||
Object createTime = metaObject.getValue(CREATE_TIME);
|
||||
if (ObjectUtil.isNull(createTime)) {
|
||||
setFieldValByName(CREATE_TIME, DateTime.now(), metaObject);
|
||||
LocalDateTime dt = LocalDateTime.now();
|
||||
String now = dt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
setFieldValByName(CREATE_TIME, now, metaObject);
|
||||
}
|
||||
} catch (ReflectionException ignored) {
|
||||
}
|
||||
} catch (ReflectionException ignored) { }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -608,11 +625,15 @@ public class GlobalConfigure implements WebMvcConfigurer {
|
|||
try {
|
||||
//设置updateUser
|
||||
setFieldValByName(UPDATE_USER, this.getUserId(), metaObject);
|
||||
} catch (ReflectionException ignored) { }
|
||||
} catch (ReflectionException ignored) {
|
||||
}
|
||||
try {
|
||||
//设置updateTime
|
||||
setFieldValByName(UPDATE_TIME, DateTime.now(), metaObject);
|
||||
} catch (ReflectionException ignored) { }
|
||||
LocalDateTime dt = LocalDateTime.now();
|
||||
String now = dt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
setFieldValByName(UPDATE_TIME, now, metaObject);
|
||||
} catch (ReflectionException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue