在《Neo4j全栈开发》一书第172页,页面采用的是thymeleaf模版引擎,页面中用到了thymeleaf标签语言strings的substring函数和length函数,使用中应该在strings前面加上#号,书中有一个加错了地方:
其中playoff.year前面的#号应该放在后面的strings.substring前面,但是书中放错了,程序就报错了。正确语法如下:
<select class="selectMode" name="pid" id="pid">
<option value="">请选择</option>
<option th:each="playoff:${playoffs}" th:value="${playoff.id}"
th:text="${#strings.length(playoff.round)>20?playoff.year+':'+#strings.substring(playoff.round,0,20)+'...':playoff.year+':'+playoff.round}"
></option>
</select>
完整的错误信息:org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'year' cannot be found on null
这个错误多半是由于thymeleaf页面标签语法有问题,请仔细检查