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;

}
相关推荐
SL_staff8 分钟前
项目延期时如何用四类角色机制实现责任锚定?一线技术实践拆解
java·低代码·团队管理
wno70412 分钟前
Spring Security Session管理
java·后端·spring
吃饱了得干活13 分钟前
主键选择:从单机到分布式,一个被低估的性能决策
java·后端
haluhalu.18 分钟前
初识 Protobuf:微服务跨语言通信的一份契约
java·c语言·开发语言·c++·python
xcl092528 分钟前
宠物商城社交托运购物系统开发实战:从架构设计到完整实现指南
java·spring boot
没差c33 分钟前
RetrofitClient写接口、导包、配置、路径
java·spring boot·okhttp
SL_staff1 小时前
MQTT Topic权限越界:JVS-IOT中系统Topic与自定义Topic的权责边界与验证实践
java·物联网·全栈
敲代码的瓦龙1 小时前
Jetpack?DataBinding!!!
android·java·开发语言·mysql·android-studio
斯维赤1 小时前
Spring AI | 结构化输出 & 多模态 一篇讲透
java·后端
程序员清风1 小时前
聊聊我的AI学习方法与思考!
java·后端·面试