赞
踩
创建RabbitMetaObjectHandler类实现MetaObjectHandler接口
@Component public class RabbitMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { this.setFieldValByName("createTime", new Date(), metaObject); String username = "system"; if (SecurityContextHolder.getContext().getAuthentication() != null) { username = SecurityContextHolder.getContext().getAuthentication().getName(); } this.setFieldValByName("createUser", username, metaObject); } @Override public void updateFill(MetaObject metaObject) { this.setFieldValByName("updateTime", new Date(), metaObject); String username = "system"; if (SecurityContextHolder.getContext().getAuthentication() != null) { username = SecurityContextHolder.getContext().getAuthentication().getName(); } this.setFieldValByName("updateUser", username, metaObject); } }
实体类需要增加配置才可生效
/** * 创建时间 */ @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date createTime; /** * 创建账号 */ @TableField(value = "CREATE_USER", fill = FieldFill.INSERT) private String createUser; /** * 更新时间 */ @TableField(value = "UPDATE_TIME", fill = FieldFill.UPDATE) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date updateTime; /** * 更新账号 */ @TableField(value = "UPDATE_USER", fill = FieldFill.UPDATE) private String updateUser;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。