html - 我如何计算表行数并在 Spring Boot 中显示输入表单?
问题描述
我正在使用带有百里香的弹簧靴。我是弹簧靴的新手。我有一个名为 Menu 的表,其中包含 column(id, menuname, url) 我已经为此表完成了 CRUD 操作。现在我想计算行数并以输入形式显示。例如,如果我有 5 行,我想让我的下拉框使用选项 1,最多行数为 1、2、3、4、5,如果我的行是 7,那么百里香下拉列表将为 1, 2,3,4,5,6,7
在我的菜单服务课上,我试试这个
@Transactional(readOnly = true)
public long getCountOfEntities() {
long count = menuRepository.count();
return count;
}
我只是卡在这里...请帮助我。
解决方案
您需要在 HTML 中为您的选择生成选项。
尝试使用 th:each 和 #numbers.sequence(from, to)
<select>
<option th:each="i : ${#numbers.sequence(1, count)}" th:value="${i}" th:text="${i}">
</option>
</select>
推荐阅读
- javascript - 盒子顺序动画
- php - 检索按类别分组的 SQL 结果
- python - 如何根据 groupby 中每个组的值最后更改的日期自动填充数据框中的数据
- python - Python在显示图像时检测x服务器错误
- bash - 如何在 bash 和/或使用 awk 的单列中进行数学运算?
- sql - SQL Server 代理作业插入的行数少于手动包执行
- ios - 如何让 CAEmitterLayer 一次只生成一个单元格 swift 4
- azure-cognitive-search - Azure 搜索查询是否支持 count(collection) > 1
- r - 如何为函数中的输出全局数据框分配名称?
- c++ - 在使用 -fsanitize=undefined (mingw-w64) 时找不到 -lubsan