im使用thymeleaf将index.html传递给包含LiveDataSet类的模型属性。但是我一直遇到这个错误。
***org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'LiveDataSet' cannot be found on object of type 'com.ex.excom.controller.LiveDataController$LiveDataSet' - maybe not public or not valid?***
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
PropertyOrFieldReference.java:217
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
PropertyOrFieldReference.java:104
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51)
PropertyOrFieldReference.java:51
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:406)
PropertyOrFieldReference.java:406
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90)
CompoundExpression.java:90
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:109)
SpelNodeImpl.java:109
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:328)
SpelExpression.java:328
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
SPELVariableExpressionEvaluator.java:263
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166)
VariableExpression.java:166
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66)
SimpleExpression.java:66
LiveDataController
@RestController
@Controller
public class LiveDataController extends BaseController
{
public class LiveDataSet
{
String getActive;
String getApparent;
String getCurrent;
String getEnergy;
}
public LiveDataSet getLiveDatas(){
...
LiveDataSet liveDatas = new LiveDataSet();
liveDatas.getCurrent = "1234"
liveDatas.getEnergy = "92.1"
...
return liveDatas
}
}
IndexController
@RequestMapping("/")
@PreAuthorize("hasAnyAuthority('ROLE_USER','ROLE_ADMIN')")
public String index(Model model, HttpSession session)
{
LiveDataSet liveData = liveDataController.getLiveDatas();
Optional<LiveDataSet> listOptLiveData = Optional.of(liveData);
listOptLiveData.ifPresent(LiveDataSet -> model.addAttribute("liveData", liveData));
return "index";
}
index.html
<tr th:each="row : ${liveData}">
<td th:text="${row.LiveDataSet}"></td>
</tr>
我如何处理此错误。数据确实存在,但我什至可以在视图中看到数据。 谢谢您阅读。
答案 0 :(得分:0)
liveData
是LiveDataSet
的一个实例。在视图中,您以${row.LiveDataSet}
的身份对其进行访问。这没有道理。 LiveDataSet
中没有任何LiveDataSet
字段!这就是为什么您会收到此错误。
答案 1 :(得分:0)
您应该访问“对象”行的属性(这是我认为的LiveDataSet的实例)
<thead>
<tr>
<td>Col1</td>
<td>Col2</td>
<td>Col3</td>
</tr>
</thead>
<tbody>
<tr th:each="row : ${liveData}">
<td th:text="${row.attr1}"></td>
<td th:text="${row.attr2}"></td>
<td th:text="${row.attr3}"></td>
</tr>
</tbdoy>
答案 2 :(得分:0)
[[$$ liveData}]]
const a = '100110100011111000100110';
const b = '111111111111111111111110';
function andBin (one, two) {
const _a = one.split('')
const _b = two.split('')
let result = ''
_a.map((e, i) => {
result += Number(e) & Number(_b[i])
})
return result
}
andBin(a, b) // 100110100011111000100110
问题是变量命名。如果我声明变量get + Active,则返回get属性,因此这会导致Java变量检测到故障,因此我更改了变量名称,并安全地返回了值。