我正在使用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
任何建议都将不胜感激!谢谢。