45.报错信息:data 和varbinary在greater than中不兼容

错误导致原因:时间分页的筛查条件时,因为传入的时间为String类型,在SQL中使用">="表示开始时间报错

入参的实体类:

java 复制代码
@Data
@ApiModel("学生列表查询的筛选条件实体类")
@AllArgsConstructor
@NoArgsConstructor
public class UserInvo{

@ApiModelProperty("年龄")
private Integr age;

@ApiModelProperty("开始时间")
private String startTime;

@ApiModelProperty("结束时间")
private String endTime;

}

UserMapper接口对应的方法:

java 复制代码
//根据条件查询学生列表
List<User> queryUserList(@Param("inVo") UserInvo userInvo );

UserMapper.xml中对应的SQL

sql 复制代码
<select id="queryUerList" returnType="User">
    select id,name,age from tb_user A
    <where>
        <if test="inVo.age=!null">
            A.age>inVo.age
        </if>
        <if test="inVo.startTime !=null">
            A.createtime &gt;=inVo.startTime
        </if>
         <if test="inVo.endTime !=null">
            A.createtime &lt;=inVo.endTime 
        </if>
    <where>
    order by A.createtime desc
</select>

    

原因:报错信息:data 和varbinary在greater than中不兼容

改正方法:分页的开始时间类型改为date,并加上时间格式(注意时间在使用if标签进行判断是否为空时,不能加上 invo.getstartTime!='',否则会导致查询数据不正确)

实体类中开始时间和结束时间修改后如下:

java 复制代码
@Data
@ApiModel("学生列表查询的筛选条件实体类")
@AllArgsConstructor
@NoArgsConstructor
public class UserInvo{

@ApiModelProperty("年龄")
private Integr age;

@ApiModelProperty("开始时间")
@DateTimeFormat(pattern = "yyyy-MM-dd ")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date startTime;

@ApiModelProperty("结束时间")
@DateTimeFormat(pattern = "yyyy-MM-dd")
 @JsonFormat(pattern = "yyyy-MM-dd ")
private Date endTime;

}
相关推荐
dd聊技术1 小时前
Prompt 从代码常量搬进数据库:改一句话,不用再发一次版
java·后端
ly76892 小时前
Spring Data MongoDB 批量写入实践:BulkOperations 批大小与写关注权衡
java·mongodb·spring·批量写入·bulkoperations·写关注·mongotemplate
TAKETODAY2 小时前
Netty 是怎么把 HTTP 请求交给 MVC 的?一个请求的完整链路
java·netty
蚰蜒螟2 小时前
从内核启动到 Java NIO:一次 socket accept 的源码串联之旅
java·python·nio
会编程的吕洞宾2 小时前
Spring AI 2.0 自校正结构化输出实战:让大模型稳定吐出合格 JSON
java·人工智能·后端·spring
bmxy小明同学2 小时前
2026-10-09-token与成本
java·前端·数据库
微笑的曙光3 小时前
第八期 · 情绪闯关挑战盒:一个「无惩罚」成就系统的数据建模
java·微信小程序
java资料站3 小时前
七、Spring AI Alibaba · Skills
java·后端·spring
code2cat4 小时前
Java进阶篇之AtomicReferenceFieldUpdater:用不可变快照替换整份状态
java·开发语言·cas
geats人山人海4 小时前
现代c++2.4 虚继承
java·开发语言·c++