mybatis逆向工程时间段查询
时间: 2023-11-09 18:01:09 浏览: 91
mybatis逆向工程本身并不支持时间段查询,但可以通过在生成的Example类中手动添加时间段查询的方法来实现。具体步骤如下:
1. 在逆向工程生成的Example类中添加两个属性,表示时间段的起始时间和结束时间,例如:
```
private Date startTime;
private Date endTime;
```
2. 在Example类中添加两个对应的Criteria方法,用于设置时间段查询条件,例如:
```
public Criteria andCreateTimeBetween(Date value1, Date value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Date value1, Date value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
```
3. 在Mapper.xml文件中使用生成的Criteria方法进行时间段查询,例如:
```
<select id="selectByExample" parameterType="com.example.demo.model.UserExample" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
<if test="example != null">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" open="(" separator=",">
#{item}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
<if test="example.startTime != null">
and create_time >= #{example.startTime}
</if>
<if test="example.endTime != null">
and create_time <= #{example.endTime}
</if>
</where>
</if>
</select>
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)