【发布时间】:2019-11-01 18:45:27
【问题描述】:
我想将用户输入的 id 作为输入并传递给控制器以获取特定 id 的数据
当我在 URL 中手动传递 id 时它正在工作 -- http://localhost:8080/student/1
<form th:action="@{{student}/{id}}" th:object="${Student}" method="post">
Roll Number:<br>
<input type="text" th:field="*{id}"><br>
<br><br>
<input class="button" type="submit" value="Submit">
</form>
@GetMapping(value = "/student/{id}")
public Optional<Student> getStudentDetail(@PathVariable int id){
return studentRepository.findById(id) ;
}
白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。
2019 年 6 月 19 日星期三 11:04:22 IST 出现意外错误(类型=内部服务器错误,状态=500)。 模板解析时出错(模板:“类路径资源[templates/student.html]”)
【问题讨论】:
标签: spring spring-boot spring-mvc thymeleaf