Spring data jpa Specification查询关于日期的范围搜索

代码:

时间格式化类型:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfmat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

 

 

try {
                if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
                    predicates.add(cb.between(root.get(“time”),
                            sdfmat.parse(sdfmat.format(sdf.parse(startTime).getTime())),
                            sdfmat.parse(sdfmat.format(sdf.parse(endTime).getTime() + 86400000))));
                }
            } catch (Exception e) {
            }

 

文章来自:http://www.cnblogs.com/mr-wuxiansheng/p/7772903.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3