From 2999d4254e5a0e66ea91b51b50fdbd693820e772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Wed, 8 Mar 2023 12:02:02 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91FreemarkerParseFac?= =?UTF-8?q?tory=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/dynamic/db/FreemarkerParseFactory.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/dynamic/db/FreemarkerParseFactory.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/dynamic/db/FreemarkerParseFactory.java index 9e01b79a..fc5e1a5f 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/dynamic/db/FreemarkerParseFactory.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/dynamic/db/FreemarkerParseFactory.java @@ -1,5 +1,6 @@ package com.jero.common.util.dynamic.db; +import com.jero.common.exception.JeroBootException; import freemarker.cache.StringTemplateLoader; import freemarker.core.ParseException; import freemarker.template.Configuration; @@ -49,7 +50,7 @@ public class FreemarkerParseFactory { static { _tplConfig.setClassForTemplateLoading( - new FreemarkerParseFactory().getClass(), "/"); + FreemarkerParseFactory.class, "/"); _tplConfig.setNumberFormat("0.#####################"); _sqlConfig.setTemplateLoader(stringTemplateLoader); _sqlConfig.setNumberFormat("0.#####################"); @@ -62,7 +63,7 @@ public class FreemarkerParseFactory { * * @throws Exception */ - public static boolean isExistTemplate(String tplName) throws Exception { + public static boolean isExistTemplate(String tplName) throws JeroBootException { try { Template mytpl = _tplConfig.getTemplate(tplName, "UTF-8"); if (mytpl == null) { @@ -72,7 +73,7 @@ public class FreemarkerParseFactory { //update-begin--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误----- if (e instanceof ParseException) { log.error(e.getMessage(), e.fillInStackTrace()); - throw new Exception(e); + throw new JeroBootException(e); } log.debug("----isExistTemplate----" + e.toString()); //update-end--Author:scott Date:20180320 for:解决问题 - 错误提示sql文件不存在,实际问题是sql freemarker用法错误------ @@ -94,7 +95,7 @@ public class FreemarkerParseFactory { StringWriter swriter = new StringWriter(); Template mytpl = _tplConfig.getTemplate(tplName, ENCODE); if (paras.containsKey(MINI_DAO_FORMAT)) { - throw new RuntimeException("DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!"); + throw new JeroBootException("DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!"); } paras.put(MINI_DAO_FORMAT, new SimpleFormat()); mytpl.process(paras, swriter); @@ -104,7 +105,7 @@ public class FreemarkerParseFactory { } catch (Exception e) { log.error(e.getMessage(), e.fillInStackTrace()); log.error("发送一次的模板key:{ " + tplName + " }"); - throw new RuntimeException("解析SQL模板异常"); + throw new JeroBootException("解析SQL模板异常"); } } @@ -124,7 +125,7 @@ public class FreemarkerParseFactory { } Template mytpl = _sqlConfig.getTemplate("sql_" + tplContent.hashCode(), ENCODE); if (paras.containsKey(MINI_DAO_FORMAT)) { - throw new RuntimeException("DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!"); + throw new JeroBootException("DaoFormat 是 minidao 保留关键字,不允许使用 ,请更改参数定义!"); } paras.put(MINI_DAO_FORMAT, new SimpleFormat()); mytpl.process(paras, swriter); @@ -134,7 +135,7 @@ public class FreemarkerParseFactory { } catch (Exception e) { log.error(e.getMessage(), e.fillInStackTrace()); log.error("发送一次的模板key:{ " + tplContent + " }"); - throw new RuntimeException("解析SQL模板异常"); + throw new JeroBootException("解析SQL模板异常"); } }