springboot API 入参 参数设置默认值 默认值为当前具体时间 当前日期
springboot API 入参 参数设置默认值 默认值为当前具体时间 当前日期
·
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
@ApiOperation(value = "测试时间当前", response = Result.class)
@GetMapping("/testLocalTime")
public Result testLocalTime(
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
@DateTimeFormat(pattern="yyyy-MM-dd")
@RequestParam(value = "start", defaultValue = "#{new java.util.Date()}", required = false) Date startDate,
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
@DateTimeFormat(pattern="yyyy-MM-dd")
@RequestParam(value = "end", defaultValue = "#{new java.util.Date()}", required = false) Date endDate) {
Date date = new java.util.Date();
System.out.println(date);
return null;
}
defaultValue = "#{new java.util.Date()}"
结果:
请求此接口时,若为设置 startDate、endDate 的值,则它们的值将为调用接口时的时间。
更多推荐
已为社区贡献1条内容
所有评论(0)