Java 更改条件中的数据类型

Java 更改条件中的数据类型,java,spring-boot,Java,Spring Boot,我有类型为double的变量vacationsPerWorkedDays,用于显示假期数量,如果当前年份在当前年份之前,则显示为固定为0 public EmployeeDashboardDto getEmployeeDashboardYearDto(Integer year, Integer employeeId) throws QOException { double vacationsPerWorkedDays = 0; if (fromDate.isBefore(dat

我有类型为
double
的变量
vacationsPerWorkedDays
,用于显示假期数量,如果当前年份在当前年份之前,则显示为固定为0

public EmployeeDashboardDto getEmployeeDashboardYearDto(Integer year, Integer employeeId) throws QOException {  
    double vacationsPerWorkedDays = 0;
    if (fromDate.isBefore(dateAct)) {
        vacationsPerWorkedDays = 0;
    }
return employeeDashboardDto;
}
我需要的是,如果它在前几年显示为
null
-
,但不更改数据类型或变量名称,因为它用于从
前端收集变量,因为它会影响其他条件。

是否有方法执行此操作,或者是否可以仅在该函数中更改数据类型?

您只需在显示写入条件时检查有效值即可

 //before returning it to frontend/UI, send it as string
 return vacationsPerWorkedDays > 0 ? ""+ vacationsPerWorkedDays : "-"

然后使用上面的
String
来显示

但新变量将显示?您可以使用现有的double检查所有条件,在显示上面的使用条件之前,我需要显示
null
-
,但不更改变量的名称,因为在使用上述条件返回返回字符串时,它将以该名称发送到前端,实际上不需要将其分配给字符串。如果混淆,请更新我的答案检查。然后,您需要在DTO中添加一个字符串以用于显示,或者需要在消费端将double转换为字符串。
           Date date  = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(cal.get(Calendar.YEAR), 0, 0);
        cal.add( Calendar.DATE, 1 );
      
     Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
       if(cal1.before(date)){
           
           return null;
           
       }else{
// your code 
}