JAVA中代码审计mongodb注入,在spring boot中进行mongodb审计以保存createdDate,lastModifiedDate,createdBy,lastModifiedBy...

我使用的是spring boot,因此我没有使用任何xml文件进行配置 . 我要做的是EnableMongoAuditing保存createdDate,lastModifiedDate等,同时使用MongoRepositories保存数据 .

我的模特课

@Component

@Document(collection = "CAPPING")

public class TemporaryCapping extends BaseEntity {

@Field("contract_id")

private BigInteger contractId;

@Field("period_id")

private BigInteger periodId;

@Field("user_id")

private BigInteger userId;

@Field("amount")

private Double amount;

@Field("type_of_capping")

private TypeOfCapping typeOfCapping;

public BigInteger getContractId() {

return contractId;

}

public void setContractId(BigInteger contractId) {

this.contractId = contractId;

}

public BigInteger getPeriodId() {

return periodId;

}

public void setPeriodId(BigInteger periodId) {

this.periodId = periodId;

}

public BigInteger getUserId() {

return userId;

}

public void setUserId(BigInteger userId) {

this.userId = userId;

}

public Double getAmount() {

return amount;

}

public void setAmount(Double amount) {

this.amount = amount;

}

public TypeOfCapping getTypeOfCapping() {

return typeOfCapping;

}

public void setTypeOfCapping(TypeOfCapping typeOfCapping) {

this.typeOfCapping = typeOfCapping;

}

}

public class BaseEntity implements Serializable{

@Id

@Indexed(unique = true)

private BigInteger id;

@CreatedDate

private DateTime createdDate;

@Field("modified_date")

private BigInteger modifiedDate;

public BigInteger getId() {

return id;

}

public void setId(BigInteger id) {

this.id = id;

}

public DateTime getCreatedDate() {

return createdDate;

}

public void setCreatedDate(DateTime createdDate) {

this.createdDate = createdDate;

}

public BigInteger getModifiedDate() {

return modifiedDate;

}

public void setModifiedDate(BigInteger modifiedDate) {

this.modifiedDate = modifiedDate;

}

我使用了@CreateDate注释来保存createDate . 我已经使用了DateTime的jodatime依赖项

joda-time

joda-time

2.9.7

spring-data-mongodb也添加在依赖项中 .

这是我的主要应用程序类

@SpringBootApplication

@EnableMongoAuditing

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

由于日期没有保存在数据库中,我在这个实施中错了?另外我知道为了保存@createdBy你需要编写AuditorAware bean但是现在我只是想保存createdBy .

应该在哪里使用@EnableMongoAuditing?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值