mybatis 中 两个时间段之间的查询

mybatis中两个时间段之间的查询

between and 没有实现想要的功能换成此方法解决

select
        <include refid="Base_Column_List" />
        from SVIP
        where  DELETE_FLAG != 1 and SVIP_STATUS =#{record.svipStatus} and RESERVE1 = #{record.reserve1} and TIME_ADD <![CDATA[>=]]> #{record.reserve11} and TIME_ADD <![CDATA[<=]]> #{record.reserve12}
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> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值