2021-04-23 02:01:18.148 ERROR 9484 --- [nioc-801.] oc. .[.[/].[dispatcherServlet] : Servlet.service() untuk servlet [dispatcherServlet] dalam konteks dengan laluan [] membuang pengecualian [Permintaan pemprosesan gagal; Pengecualian bersarang ialah freemarker.core.InvalidReferenceException: Yang berikut telah dinilai sebagai batal atau tiada:
==> hots [dalam templat "inc/right.ftl" di baris 6, lajur 11]----
Petua: Jika ungkapan yang gagal diketahui merujuk secara sah kepada sesuatu yang kadangkala batal atau tiada, sama ada tentukan nilai lalai seperti myOptionalVar!myDefault atau gunakan apabila hadirapabila hilang#if>. (Ini hanya meliputi langkah terakhir ungkapan; untuk menutup keseluruhan ungkapan, gunakan kurungan: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
------ --
Jejak tindanan FTL ("~" bermaksud berkaitan bersarang):
- Gagal di: @hots [dalam templat "inc/right.ftl" di baris 6, lajur 9]
- Dicapai melalui : #include "/inc/right.ftl" [dalam templat "index.ftl" pada baris 52, lajur 13]
~ Dicapai melalui: #nested [dalam templat "inc/layout.ftl" dalam "layout" makro di baris 25, lajur 5]
~ Dicapai melalui: @layout "首页" [dalam templat "index.ftl" di baris 2, lajur 1]
----] dengan punca utamafreemarker.core.InvalidReferenceException: Perkara berikut telah dinilai sebagai batal atau tiada:
Petua: Jika ungkapan yang gagal diketahui merujuk secara sah kepada sesuatu yang kadangkala batal atau tiada, sama ada nyatakan nilai lalai seperti myOptionalVar!myDefault atau gunakan apabila hadir. (Ini hanya meliputi langkah terakhir ungkapan; untuk menutup keseluruhan ungkapan, gunakan kurungan: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
==> -----
----
Jejak tindanan FTL ("~" bermaksud berkaitan bersarang):
- Gagal di: @hots [dalam templat "inc/right.ftl" di baris 6, lajur 9]
- Dicapai melalui: #include "/inc/right.ftl" [dalam templat "index.ftl" pada baris 52, lajur 13]
~ Dicapai melalui: #nested [dalam templat "inc/layout.ftl" dalam "reka letak" makro di baris 25, lajur 5]
~ Dicapai melalui: @layout "首页" [dalam templat "index.ftl" di baris 2, lajur 1]
----
di freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.core.UnifiedCall.accept(UnifiedCall.java:106) ~[freemarker 2.3.28.jar:2.3.28]
di freemarker.core.Environment.visit(Environment.java:330) ~[freemarker-2.3.28.jar:2.3.28]
at freemarker.core. Environment.visit(Environment.java:336) ~[freemarker-2.3.28.jar:2.3.28]
at freemarker.core.Environment.include(Environment.java:2582) ~[freemarker-2.3.28. jar:2.3.28]
at freemarker.core.Include.accept(Include.java:171) ~[freemarker-2.3.28.jar:2.3.28]
at freemarker.core.Environment.visit( Environment.java:366) ~[freemarker-2.3.28.jar:2.3.28]
at freemarker.core.Environment.invokeNestedContent(Environment.java:618) ~[freemarker-2.3.28.jar:2.3. 28]
di freemarker.core.BodyInstruction.accept(BodyInstruction.java:60) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.core.Environment.visit(Environment.java: 366) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.core.Environment.invoke(Environment.java:775) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.core.UnifiedCall.accept(UnifiedCall.java:83) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.core.Environment.visit(Environment.java:330) ~[ freemarker-2.3.28.jar:2.3.28]
di freemarker.core.Environment.visit(Environment.java:336) ~[freemarker-2.3.28.jar:2.3.28]
at freemarker. core.Environment.process(Environment.java:309) ~[freemarker-2.3.28.jar:2.3.28]
di freemarker.template.Template.process(Template.java:384) ~[freemarker-2.3. 28.jar:2.3.28]
di org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:389) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1. 4.RELEASE]
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:302) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
di org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:253) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
. org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:178) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web. servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render( DispatcherServlet.java:1370) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
di org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java) ~[1116] spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
di org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) ~[spring-webmvc-5.1.4. RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4. KELUARAN]
di org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
. springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.service HttpServlet.java:634) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
di org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring- webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
di javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.14.jar: 9.0.14]
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.tomcat.websocket.server .WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.14.jar:9.0.14]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193 ) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0 .14.jar:9.0.14]
di org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE ]
di org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.apache .catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.doFilter(ApplicationFilterChain.doFilter(ApplicationFilterChain.doFilter(ApplicationFilterChain.doFilter) .java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web -5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar :5.1.4.RELEASE]
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.springframework.web.filter.HiddenHttpMethod .doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequest0lter. ) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core -9.0.14.jar:9.0.14]
di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14 ]
di org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] bingkai di ] .web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat -embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-9.0.14.jar :9.0.14]
di org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org .apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.StandardHostValve. (StandardHostValve.java:139) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat -embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.14.jar :9.0.14]
di org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org .apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
di org.apache.coyote.AbstractProcessorLight.processor(AbstractProcessorLight.processor .java:66) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) ~[tomcat-embed -core-9.0.14.jar:9.0.14]
di org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) ~[tomcat-embed-core-9.0.14 .jar:9.0.14]
di org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
di java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.run(ThreadPoolExecutor. :628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.14.jar:9.0 .14]
di java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]2021-04-23 02:01:18.177 ERROR 9484 - -- [nio-8080-exec-1] s.e.ErrorMvcAutoConfiguration$StaticView : Tidak dapat memaparkan halaman ralat untuk permintaan [/] dan pengecualian [Yang berikut telah dinilai menjadi batal atau tiada:
==> hots [dalam templat "inc/right.ftl" di baris 6, lajur 11]----
Petua: Jika ungkapan yang gagal diketahui merujuk secara sah kepada sesuatu yang kadangkala batal atau tiada, sama ada tentukan nilai lalai seperti myOptionalVar!myDefault atau gunakan apabila hadirapabila hilang#if>. (Ini hanya meliputi langkah terakhir ungkapan; untuk menutup keseluruhan ungkapan, gunakan kurungan: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
------ --
Jejak tindanan FTL ("~" bermaksud berkaitan bersarang):
- Gagal di: @hots [dalam templat "inc/right.ftl" di baris 6, lajur 9]
- Dicapai melalui : #include "/inc/right.ftl" [dalam templat "index.ftl" pada baris 52, lajur 13]
~ Dicapai melalui: #nested [dalam templat "inc/layout.ftl" dalam "layout" makro di baris 25, lajur 5]
~ Dicapai melalui: @layout "首页" [dalam templat "index.ftl" di baris 2, lajur 1]
----] kerana respons telah pun dilakukan. Akibatnya, respons mungkin mempunyai kod status yang salah.
因为在service里试着把redis逻猁辁,然后再控制台上输出,结果发现结果是没有问题的,而且通过报错信息初步管简没找到,但是跟之前的一个类似功能相比较,然后通过不断的对比,找到问题是出在配置类。
之前一直认为template类中的getname方法就能完成映射功能>>
解决方法
springboot freemarker基础配置及使用
<!-- 引入freemarker模板引擎的依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
# 是否开启thymeleaf缓存,本地为false,生产建议为true spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.allow-request-override=false spring.freemarker.check-template-location=true #类型 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true # #文件后缀 spring.freemarker.suffix=.ftl #路径 .ftl文件就创建在templates下面或者子目录 spring.freemarker.template-loader-path=classpath:/templates/
2.1调用map类型数据,实体类也可使类也可使用用歧实体类也可使用用歧🎜>
@Controller public class FreeMarkerController { Map<String ,Object> map = new HashMap<>(); List<Object> list = new ArrayList(); @GetMapping("/freemaker/{id}/{name}") public String demo(@PathVariable("id")String id ,@PathVariable("name") String name,Model model){ map.clear(); map.put("id",id); map.put("name",name); list.add(2); list.add(4); map.put("aa",null); model.addAttribute("map",map); model.addAttribute("list",list); model.addAttribute("date",new Date()); return "index"; } }
2.2集合调用,set集合也可用此格式调用相应的元素
/*可直接获取id对应的v值*/ id:${map.id} name:${map.name}
2.3字符串拼接的两种方>法法
FreeMarker表达式中支持“+ ”、“-”、“*”、“/”、“%”运算符list01:${list[0]}
list02:${list[1]}
1. =(或者==):判断两个值是否相等;2. !=:判断两个值是否不相等;
注: =和!=可以用作字符串、数值和日期的五作字符串、数仼和日期的毆侃,必须相同。而且FreeMarker的比较是精确比较,不会忽略大小写及空格。3. >(或者gt):大于4. >=(或者gte):大于等于5. <(或者lt):小于
6. <=(或者lte):小于等于注: 上面这些比较运算符可以用于数字和日期,上面这些比较运算符可以用于数字和日期,佦不中。大部分时候,使用gt比>有更好的效果,因为FreeMarker会把>解释成标签的结束字符。可以使用括号来避免这种
<🎜月有行.><🎜天行>${"你好啊${map.name}"} ${"你好啊"+map.name}Salin selepas log masuk
2.7支持逻辑表达式
FreeMarker支持逻辑运算但是只支持布尔型逻辑运算两个辑的运算但是只支持布尔型逻辑运算两个辑的运算但是只支持布尔型逻辑运算两个运算两个记候需要添加括号才能进行逻辑运算,一般用于指令中
FreeMarker支持逻辑运算但是只支持布尔型逻辑运算两个值进行比较运算的的时候需要添加括号才能进行逻辑运算,一般用于指令中
1. &&: 逻辑与;
2. ||:逻辑或;
3. !:逻辑非
逻辑运算符只能用于布尔值。
2.8FreeMarker无法理解null值
FreeMarker的变量必须赋值,否则就会抛出异常。而对于FreeMarker来说,null值和不存在的变量是完全一样的,因为FreeMarker无法理解null值。
FreeMarker提供两个运算符来避免空值:
1.!运算
1.1若是msg不存在不报异常默认空值,若是不使用!会报异常
${msg!}
1.2若是存在则输出,若是不存在则默认为abc
${map.a!"abc"}
2.??返回布尔值一般用在指令中下面会有引用此处不解释
2.9 if指令
<#if map.aa?? > 存在 <#else > 不存在 </#if> <br> <#if (list[0]>=3) > 优秀 <#elseif (list[0]>=2)> 良好 <#else > 差劲 </#if>
2.10 list指令 遍历
<#list list as li> ${li}<br> </#list>
Atas ialah kandungan terperinci Bagaimana untuk menyelesaikan ralat apabila mengintegrasikan freemarker dalam springboot. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!