小编men*_*kan的帖子

如何使用Postman在Spring Boot中的请求参数中传递时间戳,日期

我想在 Spring Boot 控制器方法中将时间戳作为请求参数传递

//实体类

@Entity
public class EventCalendar {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private int id;
    private String eventName;
    private String city;
    private String address;
    @Temporal(TemporalType.TIMESTAMP)
    private Date createRecord;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;
    
    @Temporal(TemporalType.TIMESTAMP) 
    private Date endTime;
Run Code Online (Sandbox Code Playgroud)

//控制器

@RestController
@RequestMapping("/events")
public class controller{
    @GetMapping("/getevents8")
    public List<EventCalendar> getEvents8(@RequestParam int page,@RequestParam Date d1,@RequestParam Date d2 ){
        Sort sort=new Sort(Sort.Direction.DESC,"createRecord");
        Pageable pageRequest =PageRequest.of(page, 3,sort);
        List<EventCalendar> events;
        
            events=eventRepository.findByCreateRecordBetween(d1, d2, pageRequest);
        
        return events;
        }
}
Run Code Online (Sandbox Code Playgroud)

//我使用json插入的时间戳示例

{

        "id":10,
        "eventName":"Kabbadi pro kidz",
        "city":"Noida",
        "address":"sector 63",
        "createRecord":"2020-03-31T15:45:01Z",
        "startTime":"2020-04-08T07:30:10Z", …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-data-jpa spring-boot

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-data-jpa ×1

spring-mvc ×1