1.日期返回给前端显示不理想问题

1.1重现

不作配置返回的Date类型如下,格式不令人满意,时间也少了8个小时

{"Date": "2019-11-17T11:39:15.000+0000"}

1.2原因

没有对jackson进行时间格式配置

1.3解决

application.properties中加入对jackson的时区和Date类型格式化配置:

spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

1.4结果

{"Date": "2019-11-17 19:39:15"}

2.MyBatis-Plus数据库字段未找到问题

2.1重现

运行就抛出org.springframework.jdbc.BadSqlGrammarException:Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column 'user_name' in 'field list'异常,实体类如下:

public class User implements Serializable {
@TableId
private Long id; private String userName; }

2.2原因

MyBatis-Plus会自动将驼峰命名映射成含下划线的命名,如:userName会被转换成user_name,所以禁用这个即可。

2.3解决

application.properties中关闭映射即可:

mybatis-plus.configuration.map-underscore-to-camel-case=false

3.Long型雪花主键返回给前端精度丢失问题

3.1重现

原本为1194942865416077314的雪花主键id返回给前端变成了:

{ "id": 1194942865416077300}

3.2原因

在Long长度大于17位时会出现精度丢失的问题(具体原因有待了解)

3.3解决

在实体类上的雪花id加上注解@JsonSerialize(using=ToStringSerializer.class),将长整数转换成字符串输出处理,如:

public class User implements Serializable {
@TableId
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
}

3.4结果

{"id": "1194942865416077314"}

4.Maven依赖下载过慢

4.1原因

第一次初始化SpringBoot的时候依赖总是下到一半就卡住,因为国外网站真的是太慢了8!

初学SpringBoot遇到的坑和笔记的更多相关文章

  1. CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记

    CAS5.3服务器搭建与客户端整合SpringBoot以及踩坑笔记 cas服务器的搭建 导出证书(1和2步骤是找了课程,随便写了一下存记录,不过对于自己测试不投入使用应该不影响) C:\Users\D ...

  2. DB数据源之SpringBoot+Mybatis踏坑过程实录系列(一)

    DB数据源之SpringBoot+MyBatis踏坑过程(一) liuyuhang原创,未经允许进制转载 系列目录 DB数据源之SpringBoot+Mybatis踏坑过程实录(一) DB数据源之Sp ...

  3. 小程序——微信小程序初学踩过的坑

    微信小程序初学踩过的坑 一.前言     最近因为某些需要和个人兴趣打算开发一下微信小程序,经过在官方网站上的基本了解,我大体知道了微信小程序开发的大致过程,其实最本质的就是MVVM,借用了很多模式上 ...

  4. DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载  吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...

  5. DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载    系列目录连接 DB数据源之Spr ...

  6. DB数据源之SpringBoot+MyBatis踏坑过程(四)没有使用连接池的后果

    DB数据源之SpringBoot+MyBatis踏坑过程(四)没有使用连接池的后果 liuyuhang原创,未经允许禁止转载  系列目录连接 DB数据源之SpringBoot+Mybatis踏坑过程实 ...

  7. DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池

    DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池 liuyuhang原创,未经允许禁止转载  系列目录连接 DB数据源之SpringBoot+Mybatis踏坑 ...

  8. DB数据源之SpringBoot+MyBatis踏坑过程(七)手动使用Tomcat连接池

    DB数据源之SpringBoot+MyBatis踏坑过程(七)手动使用Tomcat连接池 liuyuhang原创,未经允许禁止转载  系列目录连接 DB数据源之SpringBoot+Mybatis踏坑 ...

  9. DB数据源之SpringBoot+MyBatis踏坑过程(六)mysql中查看连接,配置连接数量

    DB数据源之SpringBoot+MyBatis踏坑过程(六)mysql中查看连接,配置连接数量 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之SpringBoot+Mybati ...

随机推荐

  1. 求二叉树的层次遍历(SDUT 2824)

    Problem Description 已知一颗二叉树的前序遍历和中序遍历,求二叉树的层次遍历. Input 输入数据有多组,输入T,代表有T组测试数据.每组数据有两个长度小于50的字符串,第一个字符 ...

  2. poj1275

    Cashier Employment POJ - 1275 A supermarket in Tehran is open 24 hours a day every day and needs a n ...

  3. torch学习中的难点

    https://github.com/zergtant/pytorch-handbook/blob/master/chapter2/2.1.4-pytorch-basics-data-lorder.i ...

  4. VSCode查询快捷键对应功能技巧

  5. 实验吧中围在栅栏中的爱-------writeup

    涉及知识点:栅栏密码解密.摩斯密码解密.替代密码解密 题目 可以看到下面一行东西,明显是一串摩斯密码,利用CTFCrakTools将密文解密 得到另一串密码kiqlwtfcqgnsoo 那么我们尝试着 ...

  6. 03 MySQL之数据类型和运算符

    01-数据类型 MySQL支持多种数据类型,主要有 数值类型.日期/时间类型和字符串类型. 1.1 整数类型 1.2 浮点数类型和定点数类型 单精度浮点类型(FLOAT)和双精度浮点类型 (DOUBL ...

  7. 微信小程序:undefined Expecting 'STRING', got INVALID

    出现问题: 问题原因:app.json中不能出现注释

  8. 深度学习之Seq_seq网络

    知识点 """ 机器翻译: 历史: 1.逐字翻译 2.基于统计学的机器翻译 3.循环网络和编码 翻译过程: 输入 -- > encoder -->向量 --& ...

  9. python之scrapy模块下载中间件

    知识点 使用方法: 编写一个Downloader Middlewares和我们编写一个pipeline一样,定义一个类,然后在setting中开启 Downloader Middlewares默认的方 ...

  10. PCL已有点类型介绍和增加自定义的点类型

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=265 本小节不仅解释如何增加你自己的PointT点类型,也介绍了PCL中的模 ...