ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

springboot下freemarker异常页面报错信息处理全局

2021-12-01 13:31:41  阅读:205  来源: 互联网

标签:exception art springboot freemarker handler 报错 template 页面


目录

用freemarker做seo引出来一系列的问题,尤其是类似下面页面报错的问题,搞得人很烦。那有没有一种方式只记录错误日志而不用显示在页面上呢,经过多次努力试探(百度),终于找到了一种方式,在此做下记录,方便有缘人。

image-20211201131439892

配置文件

重点是:template_exception_handler我已经注释说明 后面的属性可以是Ignore /你处理freemarker异常的类

spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/art_park?useUnicode=true&characterEncoding=utf-8&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai
    username: root
    password: 'root'
  redis:
    database: 0
    host: 127.0.0.1
    password:
    port: 6379
    pool:
      max-active: 1000
      max-idle: 100
      max-wait: -1
      min-idle: 1
  freemarker:
    charset: UTF-8 # 模板编码
    content-type: text/html; charset=utf-8 # Content-Type value.
    suffix: .html # 设定模板的后缀
    template-loader-path: file:C:/soft/ideaProject/art-front/templates # 设定模板的加载路径,多个以逗号分隔,默认:
    settings:
      template_update_delay: 0
      # classic_compatible: true 这个开启就没有错误日志了 作用是过滤页面上{name}没有取到值为空的情况
      template_exception_handler: com.leshu.common.config.MyTemplateExceptionHandler
      #template_exception_handler 是用来设置freemark异常处理类的路径 如果不需要处理,template_exception_handler: Ignore 这种情况下打印不出日志
    resources:
      static-locations: file:C:/soft/ideaProject/art-front/static/ # 这个是用来从服务器上任何位置加载css img等静态资源的

异常类

大概就是这样的一个简单东西

@Component
@Slf4j
public class MyTemplateExceptionHandler implements TemplateExceptionHandler {

    @Override
    public void handleTemplateException(TemplateException templateException, Environment environment, Writer out) {
        log.error(templateException.getMessage());
    }
}

建议直接用thymeleaf,直接交给前端写就好了,freemarker前端能写出来一堆问题还要你跟着看,头疼死了,靠!!!

标签:exception,art,springboot,freemarker,handler,报错,template,页面
来源: https://www.cnblogs.com/cdong0109/p/15628525.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有