一.事故现场
今天在项目中使用thymeleaf的th:switch
标签,发生如下报错
Cannot specify a "{th:case,data-th-case}" attribute in an environment
where no switch operator has been defined before.
来张帅图:
思索三秒+百度三分钟,还是没有找到问题根源.
二.解决方案
问题卡在这里好难受,没办法去翻了以前的项目
<div th:switch="${eleInfo.invcType}">
<p th:case="'1'">正常发票</p>
<p th:case="'2'">已冲红发票</p>
</div>
而我现在的写法如下:
<span th:switch="${eleInfo.invcType}">
<p th:case="'1'">正常发票</p>
<p th:case="'2'">已冲红发票</p>
</span>
难道是<span>
标签上不能使用th:switch
?经过测试,果然在这里翻车,将<span>
换为<div>
就正常了
三.总结
经过大佬指导,猜测原因可能如下:
可能是我标签的嵌套关系有问题,<span>
标签里面不能定义<p>
标签导致了我刚刚的问题!