背景

在开发过程中,我们不可避免的需要新增数据或者修改数据。因此,无论是操作已有数据表还是新建数据表,都需要对以下几个字段进行赋值:

  • dateCreated  - 时间类型
  • dateModified - 时间类型
  • createdBy - 存储 username
  • createdByName - 存储 firstName
  • modifiedBy - 存储 username
  • modifiedByName - 存储 firstName

代码示例

WorkflowUserManager workflowUserManager = (WorkflowUserManager) AppUtil.getApplicationContext().getBean("workflowUserManager");


FormRow row = new FormRow();
Date currentDate = new Date();
row.setDateCreated(currentDate);
row.setDateModified(currentDate);
User user = workflowUserManager.getCurrentUser();
String name = null;
if (user != null) {
    name = user.getFirstName() + ((user.getLastName() != null)?(" "+ user.getLastName()):"");
}
row.setCreatedBy(workflowUserManager.getCurrentUsername());
row.setCreatedByName(name);
row.setModifiedBy(workflowUserManager.getCurrentUsername());
row.setModifiedByName(name);



  • No labels