简体   繁体   English

带有java.util.Date的QueryDSL Spring数据Web支持

[英]QueryDSL Spring data web support with java.util.Date

I'm trying to use QueryDSL Spring data web support to filter results of a REST requests based on the value of a Date passed through as a request parameter. 我正在尝试使用QueryDSL Spring数据Web支持基于作为请求参数传递的Date的值来过滤REST请求的结果。

Currently I build the predicate myself from the date passed in as a String: 目前,我是根据传入字符串的日期构建谓词的:

@GetRequest("/foos")
public List<Foo> getFoos(@RequestParam(name = "date", required = false) 
    @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
     Predicate predicate = QFoo.date.eq(date);
     ...
}

But I want to do something like: 但我想做类似的事情:

@GetRequest("/foos")
public List<Foo> getFoos(@QueryDslPredicate(root = Foo.class) Predicate predicate) {
     ...
}

But obviously it fails to parse the Date since it doesn't have any information about the pattern of the Date string anymore. 但是显然,它无法解析Date,因为它不再具有有关Date字符串模式的任何信息。 Is there any way to get this QueryDSL web support working with Date objects? 有什么方法可以使用Date对象获得此QueryDSL Web支持?

Try to add @DateTimeFormat to the entity field: 尝试将@DateTimeFormat添加到实体字段:

@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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