文章目录
- 前言
- 演示代码
- 参考仓库
前言
对于重要的一些数据,我们需要记录一条记录的所有版本变化过程,做到持续追踪,为后续问题追踪提供思路。
演示代码
下面我们通过一段代码演示代码,展示如何自动将枚举字段,主键关联字段,多行文本串,富文本内容字段自动进行转换。在此期间,你只需要配置两个注解(@LogEntity,@LogPoint)相关的属性即可实现对象日志的记录,非常方便。
@LogEntity //开启标识
public class SysUserModel extends BaseEntity {
@LogEntity(alias = "角色信息", associationValue = true, serviceImplClass = SysRoleServiceImpl.class, entityFieldName = "roleName")
//角色表存在 (9830274072323 测试角色) 这一条数据
@ApiModelProperty(name = "roleId",value = "角色表,角色id,逗号隔开")
private String roleId;
@LogEntity(alias = "用户昵称")
@ApiModelProperty(name = "userName",value = "用户昵称")
private String userName;
@LogEntity(alias = "备注" ,attributeTypeEnum = AttributeTypeEnum.TEXT)
@ApiModelProperty(name = "remark",value = "备注")
private String remark;
@LogEntity(alias = "富文本内容" , attributeTypeEnum = AttributeTypeEnum.RICHTEXT)
@ApiModelProperty(name = "richText",value = "富文本内容")
private String richText;
@LogEntity(alias = "帐号状态",enumValue = true,enumClass = StatusEnum.class)
@ApiModelProperty(name = "status",value = "帐号状态(0正常 1停用)")
private Integer status;
}
public enum StatusEnum {
NORMAL(0,"正常"),
DEACTIVATE(1,"停用"),;
//....
}
@RestController
@RequestMapping(value = "/test")
public class TestController {
@Resource
private SysUserService userService;
@Resource
private SysRoleService roleService;
@Resource
private ObjectOperationService operationService;
@GetMapping(value = "/add")
@ResponseBody
public Object testAdd(){
SysUserModel userModel = new SysUserModel();
userModel.setRoleId("9830274072323");
userModel.setUserName("哈哈");
userModel.setRemark("这是第一行\n" + "这是第二行");
userModel.setStatus(0);
userModel.setRichText("<p1>富文本<p1>");
userService.add(userModel);
}
}
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserModel> implements SysUserService {
@Override
@LogPoint( serviceHandler = SysUserServiceImpl.class, entityHandler = SysUserModel.class,
moduleName = "sysUser", remark = "测试用户模块")
public void add(SysUserModel insertModel) {
this.insert(insertModel);
}
}
结果如下图所示:
可以看到操作很简单,标记两个注解就可以了,先写到这里,累了,后面持续补充。感兴趣的朋友gitee上提issue单。源代码地址
参考仓库
gitee