bfchengnuo / MyRecord

平时充电做的笔记,一个程序猿的自我修养.
https://bfchengnuo.com/MyRecord/
33 stars 8 forks source link

Tips #59

Open bfchengnuo opened 4 years ago

bfchengnuo commented 4 years ago

Java空值检查

使用 Java7 加入的显式检查方法:Objects.requireNonNull

public static <T> T requireNonNull(T obj) {
  if (obj == null)
    throw new NullPointerException();
  return obj;
}

其他的类似 @Nullable 、断言的方法都需要手动启用相关支持,否则不会产生任何效果。 或者可以考虑 Spring 框架的断言工具类:Assert

bfchengnuo commented 4 years ago

Spring中的AOP

在 SpringBoot 2.x 中,如果需要默认使用 JDK 动态代理可以通过配置项 spring.aop.proxy-target-class=false 来进行修改,proxyTargetClass 配置已无效。

bfchengnuo commented 4 years ago

Mybatis

如果想在 Mybatis 中的 xml 映射内部静态对象,直接使用 . 的方式会报错,需要使用 $ 来进行引用。

bfchengnuo commented 3 years ago

SpringMVC中 @pathVariable 的匹配问题

如果使用 @pathVariable 进行路径匹配,路径中含有小数点的,小数点后面的内容会被忽略。

这种情况有两种处理方式; 一种是请求的时候在路径最后多加个.jpg 或者是 .其他,比如通过地址 localhost:8080/file/file.jpg.jpg 或者 localhost:8080/file/file.jpg.qwe 即可正常获取;

第二种是通过 Spring 的正则表达式规定,不做处理的 RequestMapping 是 @RequestMapping("/file/{filename}"),处理之后是 @RequestMapping("/file/{filename:.+}")

这其实是用了一个 SpEL 表达式。

bfchengnuo commented 3 years ago

MybatisPlus 使用保留字字段问题

使用保留字,MP 自带的功能并不会给我们加上转义,例如 Wrapper 查询的时候;

最简单的一个解决办法就是在对应的实体类中,加入:@TableField(value = "`value`")

参考:https://github.com/baomidou/mybatis-plus/issues/792

bfchengnuo commented 3 years ago

Docker 开启远程管理

在 centos 上测试过的:

vi /usr/lib/systemd/system/docker.service

找到 ExecStart,在最后面添加 -H tcp://0.0.0.0:2375

也就是:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

然后重启服务:

systemctl daemon-reload
systemctl restart docker

https://www.cnblogs.com/hongdada/p/11512901.html

bfchengnuo commented 2 years ago

查看 SB 的自动配置生效情况:debug: true