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;

}
相关推荐
diegoXie1 分钟前
【R】正则的惰性和贪婪匹配
java·前端·r语言
whltaoin2 小时前
【Java SE】Java IO体系深度剖析:从原理到实战的全方位讲解(包含流操作、序列化与 NIO 优化技巧)
java·开发语言·nio·se·io体系
Tony Bai9 小时前
Go 安全新提案:runtime/secret 能否终结密钥残留的噩梦?
java·开发语言·jvm·安全·golang
oioihoii9 小时前
C++11到C++23语法糖万字详解
java·c++·c++23
pengzhuofan9 小时前
Java演进与与工程师成长
java·开发语言
月明长歌9 小时前
再谈Java 继承与多态:从“能用”到“精通”,更深一层的原理与设计思维
java·开发语言
狗头实习生9 小时前
Spring常见的事务失效原因
java·数据库·spring
想个名字太难10 小时前
网络爬虫入门程序
java·爬虫·maven
diudiu_3310 小时前
web漏洞--认证缺陷
java·前端·网络
heartbeat..11 小时前
注解 + 反射:Web 项目 Excel 一键导出工具 EnhancedExportExcelUtil 详解
java·excel·poi