Springboot thymeleaf th:oncick org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context 异常


本肉肉的Springboot版本是 1.5.2正式版,经测试,与Springboot版本无关,即使是低版本的Springboot也可以指定高版本的Thymeleaf,如下图所示

 

 手动指定Thymeleaf的版本,如下图所示,  pom.xml的properties节点

 

 在使用中遇到了 org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context 异常

这个错的意思是只允许数字和布尔型,这不扯蛋嘛,瞎鸡儿报错

 

 还别说,我把参数写死成数字或者布尔值还真的挺好用,然并卵,于是我就搜啊搜

https://blog.csdn.net/u010592926/article/details/86373871   这个帖子里一共给出了四种解决方案, 我却是那第五种人

 

 

 

如上图所示,虽然做完了,功能上没任何影响,编译运行,浏览器F12统统没有任何错误,但是IDEA会提示语法错误,不知道为什么,上面那个CSDN的帖子中4种方案我都试了,统统不行,th:onclick 真是个坑,正确的IDEA却报错的代码如下

<li th:each="item : ${playList}" th:onclick="switchUrl([[${item.get('showDateTime')}]],[[${item.get('playUrl')}]])" th:text="${item.get('showDateTime')}"></li>

 

后端返回的是List<Map<String,String>> list 形式的,所以item 中使用get(String key) 获取,一开始太相信IDEA了,一报错我就删了重写,后来干脆不理它了居然成功了!


                                      是我,我是肉肉
                                                                                                                           2020年5月31日 晚上01:37
                                                                                        

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM