时间格式–cotroller传递时间参数
我们的前端控制器controller代码,
package com.forge.controller;
import com.forge.common.Result;
import com.forge.entity.Doctor;
import com.forge.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.List;
//用来生成日志对象
@Slf4j
@RestController
public class testCotroller {
@Autowired
private TestService testService;
@GetMapping("/emp")
public Result page(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "4") Integer pageSize,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
List<Doctor> doc1=testService.page(pageNum,pageSize,begin,end);
return Result.success(doc1);
}
}
我看我们的@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin
,我们使用注释@DateTimeFormat
来规定我们前端给我们的日期的格式。
我们的@RequestParam(defaultValue = "1") Integer pageNum
,我们使用@RequestParam
来进行默认值的设定。