java - 在表单的选择框部分显示数组列表
问题描述
我正在使用 Java Spring 开发一个简单的锻炼跟踪器。我正在尝试创建我的锻炼表格,该表格允许用户输入锻炼名称/重量/代表并选择他们希望添加的(先前创建的)锻炼。我查看了许多讨论类似问题的线程,但没有任何东西对我有用。
这是我的 WorkoutController 中的方法:
@PostMapping("/workout/createExercise")
public String createExercise(@ModelAttribute Exercise exercise,
Model model) {
Collection<Workout> workouts = workoutService.getWorkouts();
model.addAttribute("workouts", workouts);
workoutService.saveExercise(exercise);
return "createExercise";
}
这是表格:
<options action="#" th:action="@{/exercise/createExercise}" th:object="${exercise}" method="post">
Exercise name:<br>
<input type="text" class="formInput" name="exercise-name" size="50"
th:field="*{exerciseName}"><br>
<div class="divider"></div>
Weight:<br>
<input type="text" class="formInput" name="weight" size="50"
th:field="*{weight}"><br>
<div class="divider"></div>
Reps:<br>
<input type="text" class="formInput" name="reps" size="50"
th:field="*{reps}"><br>
<div class="divider"></div>
Workout:<br>
<select name="workout" class="exerciseForm" name="workout">
<option>--</option>
<option items="${workouts}" itemLabel="workoutName"
itemValue="workoutID"></option>
</select>
<br><br>
<input type="submit" class="input-box">
</form>
我尝试了很多变化。有时它会渲染页面但当我单击下拉框时不显示任何内容,有时它会显示以下错误:
18-11-07 12:32:47 ERROR org.thymeleaf.TemplateEngine -
[THYMELEAF][http-nio-8080-exec-10] Exception processing
template "createExercise": An error happened during
template parsing (template: "class path resource
[templates/createExercise.html]" - line 57, col 61)
org.thymeleaf.exceptions.TemplateInputException: An error
happened during template parsing (template: "class path
resource [templates/createExercise.html]" - line 57, col 61)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:239)
at
任何建议都非常感谢!谢谢。
解决方案
推荐阅读
- c# - How to define a retry policy for transient errors when publishing messages to RabbitMQ?
- flutter - Flutter:Sqflite 在未来的构建器上使用 snapshot.data.length 出错
- java - Java Graphics的fillRect(int, int, int, int)是如何实现的【低级图形编程】?
- java - 如何使用自定义字符串为类名添加前缀?
- ui-automation - 即使在 1.1.0 修复之后,空手道 switchpage 仍然无法正常工作
- sql - 如何使用 SQL 查找每个组的重复值?
- python - 使用 sudo 访问自动启动 Python
- python - 从任意维度中给定半径的线性子空间中采样随机点
- c# - 在 C# Linq 中加入客户和付款表,其中该年付款中的项目计数等于 2021 为零
- discord - go-discord-irc 对我不起作用,这是命令行上的输出