【每日小bug】——mybatis-plus拼接sql空格报错,根据时间聚合查询

发布时间:2024年01月12日

mybatis-plus拼接sql报错

在这里插入图片描述

在这里插入图片描述

复制报错sql语句到navicat,字段之间缺少空格,补上就可以了

聚合sql 根据时间

json接收
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startTime;
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endTime;
    private Integer pageNo;
    private Integer pageSize;

查询语句
xxxMapper.query(startTime , endTime , (pageNo - 1) * pageSize, pageSize)


  @Select(" select count(*) as total , " +
            "sum(collection_type = 0 )  as c0, " +
            "sum(collection_type = 1 )  as c1, " +
            "sum(collection_type = 2 )  as c2, " +
            "sum(collection_type = 3 )  as c3, " +
            "sum(collection_type = 4 )  as c4, " +
            "sum(collection_type = 5 )  as c5, " +
            "sum(collection_type = 6 )  as c6, " +
            "sum(collection_type = 7 )  as c7, " +
            "sum(collection_type = 8 )  as c8, " +
            "sum(collection_type = 9 )  as c9, " +
            "sum(collection_type = 10 )  as c10, " +
            "DATE_FORMAT( create_time, '%Y-%m-%d' )  as date " +
            "from table " +
            "where create_time BETWEEN #{startTime} and #{endTime} " +
            "group by DATE_FORMAT( create_time, '%Y-%m-%d' ) " +
            "order by DATE_FORMAT( create_time, '%Y-%m-%d' ) desc " +
            "limit #{start},#{end} ")
    List<TableVo> query(Date startTime, Date endTime, Integer start, Integer end);

结果
在这里插入图片描述

文章来源:https://blog.csdn.net/ganjiee0007/article/details/135559546
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。