1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package com.ruoyi.framework.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import org.apache.ibatis.reflection.MetaObject;
import java.util.Date;
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
private static String getUserName() { String username = null; try { username = SecurityUtils.getUsername(); } catch (Exception e) { } return username; }
@Override public void insertFill(MetaObject metaObject) { this.strictInsertFill(metaObject, "createTime", Date.class, new Date()); String userName = getUserName(); if (StringUtils.isNotEmpty(userName)) { this.strictInsertFill(metaObject, "createBy", String.class, userName); } }
@Override public void updateFill(MetaObject metaObject) { this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date()); String userName = getUserName(); if (StringUtils.isNotEmpty(userName)) { this.strictUpdateFill(metaObject, "updateBy", String.class, userName); } } }
|