如何使用springboot

时间:2019-05-01 15:38:15

标签: java spring spring-boot calendar

我有这个以下json对象:

{
"username":"test",
"customerName":"test",
"accessReasons":"tes",
"leaseHours":"8"
}

这表示特定用户必须执行特定任务的时间(即sysdate + leaseHours)

在我的控制器上,我创建了一个对象,其中包含在json中收到的信息:

thatObject obj=new thatObject (jsonObjectFromPostBody)

这样做,将通过以下方式创建thatObject的实例:

public thatObject(thatObject aci) {
    this.username=aci.getUsername();
    this.customerName=aci.getCustomerName();
    this.accessReasons=aci.getAccessReasons();
    this.beginDate= new GregorianCalendar();
    long sum=beginDate.getTimeInMillis()+aci.getLeaseHours().getTimeInMillis();
    this.endDate=(Calendar)beginDate.clone();
    this.endDate.setTimeInMillis(sum);
}

您可以看到,我的endDate是纪念日+用户有权激活的时间(在本例中为8小时)

但是我的问题是我正在使用日历,无法在json对象上表示这8小时,所以当我计算endTime时,它将为0,我如何在json上表示这8小时或将这8小时加起来到我的beginDate变量?

1 个答案:

答案 0 :(得分:0)

为什么不只是在 thatObject 中将 leaseHours 属性的类型更改为 Integer ? 在这种情况下,您可以执行以下操作:

long sum=beginDate.getTimeInMillis() + aci * 60 * 60 * 1000;