org.springframework.Ausdruck.spel.SpelEvaluationException: EL1008E:(pos 8): die Eigenschaft oder das Feld
Schreibe ich ein sample-code mit spring boot ,jpa mit Thymeleaf. Hier ist mein code, ich konnte sehen, wie die kommenden Daten bis zum Controller, aber keine Anzeige aufgrund von unten Ausnahme. Ihre Hilfe wird sehr geschätzt.
Controller:
@Controller
@RequestMapping("/account")
public class AccountController {
@Autowired
AccountRepository accountRepository;
@RequestMapping("/")
public String list(ModelMap modelMap){
List<Account> accounts = (List<Account>) accountRepository.findAll();
modelMap.put("accounts", accounts);
//return accountRepository.findAll();
return "account";
}
Entity:
@Entity
public class Account {
@Id
@GeneratedValue
private Integer accountId;
private String name;
private String accType;
public Integer getAccountId() {
return accountId;
}
public String getName() {
return name;
}
public String getAccType() {
return accType;
}
public Account(Integer accountId, String name, String accType) {
super();
this.accountId = accountId;
this.name = name;
this.accType = accType;
}
account.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<h1> Account Management</h1>
<table border="2">
<tr>
<th>Account Id</th>
<th>Name</th>
<th>Account Type</th>
</tr>
<tr th:each="account : accounts">
<td th:text="${account.accountId}"/>
<td th:text="${account.name}"/>
<td th:text="${account.accType}"/>
</tr>
</table>
<a href="/">Back</a>
</body>
</html>
Exception Stack trace:
2016-10-12 14:51:56.263 ERROR 32572 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "account": Exception evaluating SpringEL expression: "account.accountId" (account:17)
2016-10-12 14:51:56.269 ERROR 32572 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "account.accountId" (account:17)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 8): Property or field 'accountId' cannot be found on object of type 'java.lang.String' - maybe not public?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:267) ~[spring-expression-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.thymeleaf.spring4.expression.SpelVariableExpressionEvaluator.evaluate(SpelVariableExpressionEvaluator.java:139) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariable(VariableExpression.java:154) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:59) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:103) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:133) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:120) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.standard.processor.attr.AbstractStandardTextChildModifierAttrProcessor.getText(AbstractStandardTextChildModifierAttrProcessor.java:68) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor.getModifiedChildren(AbstractTextChildModifierAttrProcessor.java:59) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.attr.AbstractChildrenModifierAttrProcessor.processAttribute(AbstractChildrenModifierAttrProcessor.java:59) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1017) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
Du musst angemeldet sein, um einen Kommentar abzugeben.
Diese:
sollte
Es ist nicht die Lösung "Konten" als variable, so, wenn Sie Sie später verwenden ${Konto.accountId}, es ist nicht in der Lage zu beurteilen, dass der Ausdruck korrekt.
In meinem Fall war ich Sortieren einer Liste mit
th:each="company : ${#lists.sort(allCompanys)}"
aber vergessen zu implementieren
Comparable<Company>