Chuenhung的个人网站

chuenhung.github.io

Hexo博客 Next主题图片防盗链问题

问题场景:打开博客,所有引用外部链接的图片均无法正常加载,但是所有图片复制链接在浏览器请求是可以加载的。
问题原因:目标网站图片设置了防盗链。
解决方案:在 \themes\next\layout_partials\head.swig文件中加一行代码即可。
在这里插入图片描述
参考链接参考链接

Springboot Druid数据库密码加密配置步骤

方式一:

  • 找到druid包的位置,CMD命令行执行下面的命令
1
java -cp druid-1.2.6.jar com.alibaba.druid.filter.config.ConfigTools 数据库密码 > pwd.txt
  • 把项目中的解密公钥和密文改为pwd.txt中的publicKey、password
阅读全文 »

Spring缓存相关注解

@Cacheable注解

对于一个使用@Cacheable标注的方法,Spring会在其被调用后将其返回值缓存起来,以保证下次利用同样的参数来执行该方法时可以直接从缓存中获取结果,而不需要再次执行该方法。
cacheNames和value这两个属性任意使用一个都可以,且必须指定,否则会报错。它们的作用可以理解为key的前缀。

1、key和value都指定

1
@Cacheable(key = "'testKey'", value = "testValue")

生成的Redis键格式为:testValue::testKey

在这里插入图片描述

2、key和cacheNames都指定

1
@Cacheable(cacheNames = {"testNames","testNamesTwo"}, key = "'testKey'")

会生成多个Redis键,格式为:testNames::testKey
在这里插入图片描述

阅读全文 »

对象List处理

List转为HashMap

利用Collectors.toMap方法实现,若重复Key则覆盖。

1
2
3
4
5
6
7
8
9
10
// 值为对象
Map<String, Account> map = accountList.stream().collect(Collectors.toMap(Account::getUsername, Function.identity(), (key1, key2) -> key2));
// 值为字段
Map<Long, String> map = accountList.stream().collect(Collectors.toMap(Account::getId, Account::getUsername,(key1, key2) -> key2));
// 自定义键值
Map<String, String> dbCompanyFiledMap = dbCompanyFiledList.stream()
.collect(Collectors.toMap(
companyFiled -> companyFiled.getCompanyId() + companyFiled.getCompanyFiled(),//键
AchievementCompanyFiled::getReGroupFiled, //值
(key1, key2) -> key2));
阅读全文 »

实现逻辑

自定义渲染策略实现逻辑:

  • 找到模板中的表格标签
  • render方法接收java中对应模板表格标签的所有list数据
  • 执行自定义渲染逻辑

参考代码

word模板如下:
在这里插入图片描述

阅读全文 »
0%