java - 为什么我的 GetMapping 注释没有被识别
问题描述
所以这是我的控制器。首先,这里我有 GET 和 POST 两种请求方法,但由于某些奇怪的原因,GetMapping("/journeys")
无法识别。
@Controller
@GetMapping("/journeys")
String journeys(Model model , @Valid JourneyForm form) {
model.addAttribute("journeys", journeys.findAll()) ;
model.addAttribute("form", form);
return "journeys" ;}
@GetMapping("/jounreyCreate")
String createJourney(Model model , JourneyForm form){
model.addAttribute("form", form) ;
return "journeyCreate" ;
}
@PostMapping("/journeyCreate")
String createJourney(Model model ,Errors errors,@Valid @ModelAttribute("form") JourneyForm form ) {
if (errors.hasErrors()) {
return journeys(model , form);
}
journeys.save( form.createJourney() ) ;
return "redirect:/journeys";
}
这是 JourneyForm 类
public class JourneyForm {
private String name;
public JourneyForm(String name) {
this.name = name ;
}
public String getName() {
return name;
}
public Journey createJourney() {
return new Journey(getName());
}
}
最后一部分是journey.html
和journeyCreate.html
<body>
<h2 th:text="#{journeys.title}">Reise</h2>
<a href="/journeyCreate">
<button class="ui button">Journey erstellen</button>
</a>
<a href="/journeyEdit">
<button class="ui button">Reise bearbeiten</button>
</a>
<div th:each="journey : ${journeys}">
<p th:text="'Reise: '+${journey.name}">Reise</p>
</div>
和journeyCreate.html
<a href="/journeys">
<button class="ui button">Zurück zur Reise</button>
</a>
<form role="form" class="ui form" id="form" th:object="${form}" th:method="post" th:action="@{/journeyCreate}">
<div class="field">
<label for="journeyName">Name</label>
<input id="journeyName" name="journeyName" type="text" th:field="*{name}" th:errorclass="is-invalid" required="required"/><br/>
<div th:if="${#fields.hasErrors('name')}" class="invalid-feedback">Please provide a name.</div>
</div>
<input type="submit" value="Submit">
</form>
这真的很令人沮丧,我无法理解原因
您的帮助将不胜感激,谢谢。
解决方案
推荐阅读
- neo4j - Neo4j 将 JSON 结果转换为数组
- python - 使用 HTTP 条件标头上传 Blob
- javascript - 从 CSV 到带有库 PapaParse 的 JSON:139.420248 =>“139.420.248”?
- python - 制作scrapy.Request确定性?
- python - 如何使用 anaconda 将 pytorch 版本从 0.4 降级到 0.31?
- reactjs - 如果将函数(返回随机图像 url)作为 uri 参数传递并且状态发生更改,则反应原生更改图像
- java - 将查询结果从一个数据库的多个连接表复制到另一个数据库的最佳实践?
- php - 如何在 laravel 中创建一个自动函数?
- google-chrome - 将 UI5 资源升级到 1.54 后,在本地引导 SAPUI5 应用程序会引发错误
- jquery - 我无法得到这个改变宽度以运行不止一次的 jQuery 动画