<select id="selectSysRpuserListByToday" parameterType="SysRpuser" resultMap="SysRpuserResult"> <include refid="selectSysRpuserVo"/> <where> <if test="tid != null and tid != ''"> and tid = #{tid}</if> <if test="tusername != null and tusername != ''"> and tusername like concat('%', #{tusername}, '%')</if> <if test="tnickname != null and tnickname != ''"> and tnickname like concat('%', #{tnickname}, '%')</if> <if test="uamount != null and uamount != ''"> and uamount = #{uamount}</if> <if test="ustatus != null and ustatus != ''"> and ustatus = #{ustatus}</if> <if test="forgroup != null and forgroup != ''"> and forgroup = #{forgroup}</if> <if test="createtime != null "> and createtime = #{createtime}</if> <if test="agentTid != null and agentTid != ''"> and agentTid = #{agentTid}</if> </where> </select>优化以上代码,要求能查询当日数据
时间: 2024-03-24 22:36:30 浏览: 195
可以在 `<where>` 标签中添加对 `createtime` 字段的判断,使查询仅返回当日的数据。具体代码如下:
```xml
<select id="selectSysRpuserListByToday" parameterType="SysRpuser" resultMap="SysRpuserResult">
<include refid="selectSysRpuserVo"/>
<where>
<if test="tid != null and tid != ''"> and tid = #{tid}</if>
<if test="tusername != null and tusername != ''"> and tusername like concat('%', #{tusername}, '%')</if>
<if test="tnickname != null and tnickname != ''"> and tnickname like concat('%', #{tnickname}, '%')</if>
<if test="uamount != null and uamount != ''"> and uamount = #{uamount}</if>
<if test="ustatus != null and ustatus != ''"> and ustatus = #{ustatus}</if>
<if test="forgroup != null and forgroup != ''"> and forgroup = #{forgroup}</if>
<!-- 添加当日数据判断 -->
<if test="createtime != null">
and createtime >= #{createtime}
and createtime <= DATE_ADD(#{createtime}, INTERVAL 1 DAY)
</if>
<if test="agentTid != null and agentTid != ''"> and agentTid = #{agentTid}</if>
</where>
</select>
```
这个代码中,`DATE_ADD(#{createtime}, INTERVAL 1 DAY)` 表示将 `#{createtime}` 的日期加 1 天,相当于查询当日的数据。
在Java代码中,可以这样调用:
```java
SysRpuser obj = new SysRpuser();
obj.setCreatetime(new Date());
List<SysRpuserResult> result = sqlSession.selectList("selectSysRpuserListByToday", obj);
```
这样,就可以查询出当日的数据了。
阅读全文
相关推荐
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)