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. pat 甲级 1045 ( Favorite Color Stripe ) (动态规划 )

    1045 Favorite Color Stripe (30 分) Eva is trying to make her own color stripe out of a given one. She ...

  2. Cogs 734. [网络流24题] 方格取数问题(最大闭合子图)

    [网络流24题] 方格取数问题 ★★☆ 输入文件:grid.in 输出文件:grid.out 简单对比 时间限制:1 s 内存限制:128 MB «问题描述: 在一个有m*n 个方格的棋盘中,每个方格 ...

  3. 【原创】洛谷 LUOGU P3366 【模板】最小生成树

    P3366 [模板]最小生成树 题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N ...

  4. IDEA项目结构只剩下了pom,而代码都找不到了

    大体效果就是下面这个样子的, 只剩下一个pom文件了. 解决方式: 本来想彻底排查下的,但是最后发现 直接删除.idea文件, 重新引入项目,就可以解决,可能就是编译器发神经吧 下面是排查的过程,不过 ...

  5. Elasticsearch6.5.1破解x-pack,设置密码并使用head插件登陆。

    #没有许可证的es无法持久的设置密码,而且使用一段时间后会过期,过期后,一些功能无法被使用,例如head插件无法看到es状态. 下图是过期的es的状态,可通过此url查看:http://ip:port ...

  6. mysql数据库引擎——MyISAM,InnoDB

    作为一个java web开发人员,对于mysql数据库掌握到具体比较这两类引擎的差异也蛮拼的,下面就介绍一下我在工作中积累的对这两类引擎的理解. MyISAM: 如果不更改mysql配置文件(my.i ...

  7. 1.springboot内置tomcat的connection相关

    最近在研究tomcat的连接超时问题,环境:jdk1.8 + springboot 2.1.1.RELEASE,以下仅为个人理解,如果异议,欢迎指正. springboot的tomcat的几个配置参数 ...

  8. LC 813. Largest Sum of Averages

    We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the su ...

  9. LC 871. Minimum Number of Refueling Stops 【lock, hard】

    A car travels from a starting position to a destination which is target miles east of the starting p ...

  10. css sprite 雪碧图

    使用雪碧图的目的:有时为了美观,我们会使用一张图片来代替一些小图标,但是一个网页可能有很多很多的小图标,浏览器在显示页面的时候,就需要像服务器发送很多次访问请求, 这样一来,一是造成资源浪费,二是会导 ...