У меня есть этот фрагмент кода в шаблоне Thymeleaf
var theList = /*[[${route}]]*/
for (i = 0; i < theList.length; i++) {
var coordinate = [/*[[${theList[i].longitude}]]*/,/*[[${theList[i].latitude}]]*/];
coordinates2.push(coordinate);
}
но когда объект ${route} не равен нулю, это пустой список, который я помещаю в контроллер:
List<Coordinate> route = new ArrayList<Coordinate>();
model.addAttribute("route", route);
У меня такая ошибка:
org.springframework.expression.spel.SpelEvaluationException: EL1012E: Cannot index into a null value
at org.springframework.expression.spel.ast.Indexer.getValueRef(Indexer.java:132)
at org.springframework.expression.spel.ast.Indexer.getValueInternal(Indexer.java:89)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:57)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:121)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:324)




Вы не можете смешивать переменные JavaScript и Thymeleaf. Переменная i определена в цикле JavaScript for (for (i = 0; i < theList.length; i++)), но вы пытаетесь использовать ее в выражении Тимелист. Вы должны держать их отдельно.
var theList = /*[[${route}]]*/ [];
for (i = 0; i < theList.length; i++) {
var coordinate = [theList[i].longitude, theList[i].latitude];
coordinates2.push(coordinate);
}