MySQL相关问题
本章节记录使用MySql过程中遇到的一些问题
Delete表别名问题
MySQL是支持表别名的,但是按照正常select语句书写可能会报错:
delete from t_package_check_task t where t.user_id='test2019';
报错结果如下:
> 1064 - You have an error in your SQL syntax;
> check the manual that corresponds to your MySQL server version for the right syntax to use near 't where t.user_id='test9901'' at line 1
正确的delete使用表名的语法应当是这样
delete t from t_package_check_task t where t.user_id='test2019';
delete t from t_package_check_task t where t.user_id=‘test2019’;跟上面的语句唯一的差别就是在delete后面加上了表的别名t,这才是正确的语法,当然实际上像这种简单的sql语句使用别名的意义不大,可以直接不使用别名完成delete操作。
delete from t_package_check_task where user_id='test2019';
Java8相关问题
新的时间类
第一部分的时间类都是不涉及时区的
Instant
//Instant表示一个时间戳,入参的单位为毫秒
Instant.ofEpochMilli(long epochMilli);
//入参的单位为秒
Instant.ofEpochSecond(long epochSecond);
//入参的单位为秒加纳秒
Instant.ofEpochSecond(long epochSecond, long nanoAdjustment);
LocalDate
//获取当前日期
LocalDate.now();
//获取某年某月某日LocalDate对象
LocalDate.of(int hour, int minute, int second, int nanoOfSecond);
LocalTime
//获取当前时间,精确到毫秒
LocalTime.now();
//获取某时某分某秒某毫秒LocalTime对象
LocalTime.of(int hour, int minute, int second, int nanoOfSecond);
LocalDateTime
//获取当前日期和时间,精确到毫秒
LocalDateTime.now();
//获取LocalDateTime对象
LocalTime.of(LocalDate date, LocalTime time);
Period
// 2019-12-09 10:07:00
LocalDateTime from = LocalDateTime.of(2019, Month.DECEMBER, 9, 10, 7, 0);
// 2019-12-11 9:07:00
LocalDateTime to = LocalDateTime.of(2019, Month.DECEMBER, 11, 9, 7, 0);
//2019-12-09 10:07:00到2019-12-11 9:07:00之间的时间段
Period period = Period.between(from.toLocalDate(), to.toLocalDate());
//获取固定年月日时长的时间段
Period.of(int years, int months, int days)
//时间段转化为天数,只看日期的跨度,比如9号到11号输出就是2天,9号到9号输出就是0天
int days = period.getDays();
Duration
// 2019-12-09 10:07:00
LocalDateTime from = LocalDateTime.of(2019, Month.DECEMBER, 9, 10, 7, 0);
// 2019-12-11 9:07:00
LocalDateTime to = LocalDateTime.of(2019, Month.DECEMBER, 11, 9, 7, 0);
//2019-12-09 10:07:00到2019-12-11 9:07:00之间的时间段
Duration duration = Duration.between(from, to);
//获取amout+unit的时间段,其中unit为时间单位,天,小时,分钟等
Duration.of(long amount, TemporalUnit unit)
//时间段转化为天数,结果就是duration对象中的秒数second整除每天的秒数
int days = duration.toDays();
接下来部分的时间类,涉及到时区变化