实体类
package com.yunhe.jvmjiazai;
import java.util.Date;
/**
* @author by houbing
* @date 2022/6/20 20:22
* @Classname Order
* @Description TODO
*/
public class Order {
private String name;
private Date createTime;//订单的创建时间,保存到数据库中,在数据库中类型为timestamp
private String beginTime;//前端传到后端的开始时间,不需要保存数据库中
private String endTime;//前端传到后端的结束时间,不需要保存数据库中
public Order() {
}
public Order(String name, Date createTime, String beginTime, String endTime) {
this.name = name;
this.createTime = createTime;
this.beginTime = beginTime;
this.endTime = endTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getBeginTime() {
return beginTime;
}
public void setBeginTime(String beginTime) {
this.beginTime = beginTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
@Override
public String toString() {
return "Order{" +
"name='" + name + '\'' +
", createTime=" + createTime +
", beginTime='" + beginTime + '\'' +
", endTime='" + endTime + '\'' +
'}';
}
}
这里我用的数据库语言是 postgresql ,在日期上处理不同于MySQL数据库
查询在开始时间到结束时间中所有创建的订单信息(开始时间与结束时间均是前端传来的)
<select id="findLike" resultType="com.yunhe.entity.Order">
select *
from order
<where>
<if test="beginTime!=null and beginTime!=''">
and createTime >= to_date(#{beginTime},'yyyy-mm-dd')
<--and createTime >= to_date(#{beginTime}, 'yyyy-mm-dd')-->
</if>
<if test="endTime!=null and endTime!=''">
and createTime < to_date(#{endTime},'yyyy-mm-dd')
<--and createTime <= to_date(#{endTime}, 'yyyy-mm-dd')-->
</if>
</where>
</select>