今天遇到了条件中使用时间参数,数据库是Oracle的,查阅MyBatis Plus QueryWrapper 默认提供的几个方式都不行,
这种时间查询
// 预警时间
if (warning.getWarningTimeParams() != null
&& warning.getWarningTimeParams().get("beginTime") != null
&& warning.getWarningTimeParams().get("beginTime") != ""
&& warning.getWarningTimeParams().get("endTime") != null
&& warning.getWarningTimeParams().get("endTime") != "") {
qw.apply("warning_time >= TO_DATE({0}, 'yyyy-MM-dd HH24:mi:ss')", warning.getWarningTimeParams().get("beginTime"));
qw.apply("warning_time <= TO_DATE({0}, 'yyyy-MM-dd HH24:mi:ss')", warning.getWarningTimeParams().get("endTime"));
}
// 处理时间
if (warning.getUpdateTimeParams() != null
&& warning.getUpdateTimeParams().get("beginTime") != null
&& warning.getUpdateTimeParams().get("beginTime") != ""
&& warning.getUpdateTimeParams().get("endTime") != null
&& warning.getUpdateTimeParams().get("endTime") != "") {
qw.apply("update_time >= TO_DATE({0}, 'yyyy-MM-dd HH24:mi:ss')", warning.getUpdateTimeParams().get("beginTime"));
qw.apply("update_time <= TO_DATE({0}, 'yyyy-MM-dd HH24:mi:ss')", warning.getUpdateTimeParams().get("endTime"));
}
// dao中的字段
@TableField(exist = false)
private Map<String, Object> warningTimeParams;
@TableField(exist = false)
private Map<String, Object> updateTimeParams;
普通的时间搜索
if (device.getParams() != null
&& device.getParams().get("beginTime") != null
&& device.getParams().get("beginTime") != ""
&& device.getParams().get("endTime") != null
&& device.getParams().get("endTime") != "") {
qw.between("create_time", device.getParams().get("beginTime") + " 00:00:00", device.getParams().get("endTime") + " 23:59:59");
}