看公司代码时的一些记录

freemarker中加载不了其他文件,服务器显示404.
这里写图片描述

1.ApplicationListener 监听器

2.容器加载完毕做一件事(利用ContextRefreshedEvent事件):很多时候我们想要在某个类加载完毕时干某件事情,但是使用了spring管理对象,我们这个类引用了其他类(可能是更复杂的关联),所以当我们去使用这个类做事情时发现报空指针错误,这是因为我们这个类有可能已经初始化完成,但是引用的其他类不一定初始化完成,所以发生了空指针错误

3.WebMvcConfigurerAdapter

4.freemarker.template.Configuration.setSharedVariable()

官方api是这样说的
SharedVariables are variables that are defined for all templates..
You can add shared variables to the configuration with the setSharedVariable methods:

Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
...
cfg.setSharedVariable("warp", new WarpDirective());
cfg.setSharedVariable("company", "Foo Inc.");

问题解决:application.yml中的classic_compatible和auto_import缺一不可

freemarker:
    content-type: text/html
    suffix: .html
    settings:
      classic_compatible: true
      auto_import: /ftl/pony/index.ftl as p,/ftl/spring.ftl as s,/pages/global/ztitle.html as z

下面这句话的意思是页面文件中引入的外部文件都放在/mag/res文件夹中

        cfg.setSharedVariable("res", propMy.getResbase());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值