6.3 通过数据的懒惰检索实现优化
实际上,这可以被应用到任何一块数据。这种场景的最普遍案例是给出集合在内存中的大小,遍历检索数据。context.setVariable(
"users",
new LazyContextVariable<List<User>>() {
@Override
protected List<User> loadValue() {
return databaseRepository.findAllUsers();
}
});<ul>
<li th:each="u : ${users}" th:text="${u.name}">user name</li>
</ul><ul th:if="${condition}">
<li th:each="u : ${users}" th:text="${u.name}">user name</li>
</ul>Last updated