获得徽章 0
- 2023的最后一天班,简单记录一下给自己个仪式感。
今日工作:很无语的把之前搭好的项目(业务代码基本写完了)换到公司新框架上,并且新框架是没SQL Server版本,折磨很久后还好换了过来。坐等下班,心已不在,祝诸君元旦假期快乐。
希望来年涨薪涨薪涨薪💴等人赞过评论4 - MySQL JDBC 驱动在默认情况下会无视 executeBatch()语句,把我们期望批量执行的一组 sql 语句拆散,一条一条地发给 MySQL 数据库,批量插入实际上是单条插入,直接造成较低的性能。只有把 rewriteBatchedStatements 参数置为 true, 驱动才会帮你批量执行 SQL。另外这个选项对 INSERT/UPDATE/DELETE 都有效。
rewriteBatchedStatements=true 的意思是,当你在 Java 程序中使用批量插入/修改/删除(batching)时,MySQL JDBC 驱动程序将尝试重新编写(rewrite)你的 SQL 语句,以便更有效地执行这些批量插入操作。
MySQL 的 JDBC 连接的 url 中要加 rewriteBatchedStatements 参数,并保证 5.1.13 以上版本的驱动,才能实现高性能的批量插入。
spring:
datasource:
url: jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf-8&serverTimezone=UTC&rewriteBatchedStatements=true展开等人赞过评论5 - 随记--Java实现树状结构数据模糊查询
public static void treeMatch(List<SceneLabelPo> allLabel, String keyword) {
Iterator<SceneLabelPo> iter = allLabel.iterator();
while (iter.hasNext()) {
// 获取当前遍历到的目录
SceneLabelPo label = iter.next();
// 如果当前目录名称包含关键字,则什么也不做(不移除),否则就看下一级
if (!label.getLabelName().contains(keyword)) {
// 取出下一级目录集合
List<SceneLabelPo> childrenLabelList = label.getChildren();
// 递归
if (!CollectionUtils.isEmpty(childrenLabelList)) {
treeMatch(childrenLabelList, keyword);
}
// 下一级目录看完了,如果下一级目录全部被移除,则移除当前目录
if (CollectionUtils.isEmpty(label.getChildren())) {
iter.remove();
}
}
}
}展开等人赞过评论5 - 随记--极简版日志AOP
@Component
@Aspect
public class LogAspect {
@Pointcut("execution(* org.example.controller.*.*(..))")
public void asp() {
}
@Before("asp()")
public void beforeAsp(JoinPoint joinPoint) {
System.out.println("执行开始");
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
System.out.println("请求来源-->" + request.getRemoteAddr());
System.out.println("请求URL-->" + request.getRequestURL().toString());
System.out.println("请求方式-->" + request.getMethod());
System.out.println("响应方法-->" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
System.out.println("请求参数-->" + Arrays.toString(joinPoint.getArgs()));
System.out.println("执行完成");
}
}展开赞过评论3 - 随记--近三周
Date currentDate = new Date();
Calendar calendar = Calendar.getInstance();
// 设置一周的周一为第一天,很重要
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(currentDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 上上周
calendar.add(WEEK_OF_YEAR, -2);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
Date firstDayOfBeforeBeforeWeek = calendar.getTime();
String firstDayOfBeforeBeforeWeekDate = sdf.format(firstDayOfBeforeBeforeWeek);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
Date lastDayOfBeforeBeforeWeek = calendar.getTime();
String lastDayOfBeforeBeforeWeekDate = sdf.format(lastDayOfBeforeBeforeWeek);
// 上周
calendar.add(WEEK_OF_YEAR, 1);
……
// 本周
……
// 下周
……
// 下下周
……展开等人赞过24 - 日期获取一年时间段
方式一:
LocalDate now = LocalDate.now();
// 去年的本月1号
LocalDate lastYearFirstDayOfMonth = now.minusYears(1).with(TemporalAdjusters.firstDayOfMonth());
// 本月最后一天
LocalDate currentYearLastDayOfMonth = now.with(TemporalAdjusters.lastDayOfMonth());
//一天中开始时间(0点)
LocalDateTime oneYearAgoTime = lastYearFirstDayOfMonth.atStartay();
//一天中结束时间(23点59分59秒)
LocalDateTime currentDateTime = LocalDateTime.of(currentYearLastDayOfMonth, LocalTime.MAX);展开赞过53 - 随记
时间范围包含确认
queryWrapper
.and(x -> x
.or().or(x1 -> x1
.ge(Entity::getDueDate, startDate).le(Entity::getDueDate, endDate))
.or().or(x2 -> x2
.ge(Entity::getStartDate, startDate).le(Entity::getStartDate, endDate))
.or().or(x3 -> x3
.le(Entity::getStartDate, startDate).ge(Entity::getDueDate, endDate)));展开等人赞过14 - 随记
今日奇怪bug,bigint导致前端接收数据精度丢失,本地接口测试无误
后在实体字段添加@JsonFormat(shape = JsonFormat.Shape.STRING)注解,问题解决。
留下日后研究等人赞过66 - 随记
IDEA快捷键--显示方法参数提醒
配置:File->Settings->Editor->General->Code Completion->Parameter Info(勾选三个选项)->Apply
快捷键:方法处按CTRL+P等人赞过评论6