简体   繁体   中英

Always save date to today's date in database using jhipster

I have created one entity in jhipster using jhipster-jdl.jh file which is as shown below:

entity EmployeeLeave{
    appliedDate LocalDate required,
    fromDate    LocalDate required,
    toDate  LocalDate required,
    status String
}

From these fields i want appliedDate as today's date in database(MySql). I have tried this from Angular side in jhipster code but none helps well.

Is there any way so that when creating a record for employeeLeave there should be always appliedDate equals to today's date. Preferably i want solution from Angular side. Other solutions are also welcomed.

Technologies:

Database: Mysql, Spring-boot, Angular 4, Jhipster.

You can initialize your date inside your class :

public class EmployeeLeave{
   LocaleDate yourDate = LocaleDate.now();
   //other fields
}

So, appliedDate will always be today's date. I am using Java 8 but the idea is here.

LocaleDate.now() is server time. If server is in another time zone than user, may insert incorrect date. Isn't better to define date in .controller.js like:

                        var now = new Date();
                        vm.employeeLeave.appliedDate=now;
                        vm.isSaving = true;
                        EmployeeLeave.update(vm.employeeLeave, onSaveSuccess, onSaveError);

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM