Java 为什么无法识别我的GetMapping注释
这是我的控制器。首先,这里我有两个请求方法GET和POST,但是由于某种奇怪的原因,Java 为什么无法识别我的GetMapping注释,java,spring-mvc,request-mapping,get-mapping,Java,Spring Mvc,Request Mapping,Get Mapping,这是我的控制器。首先,这里我有两个请求方法GET和POST,但是由于某种奇怪的原因,GetMapping(“/journes”)没有被识别 @Controller @GetMapping("/journeys") String journeys(Model model , @Valid JourneyForm form) { model.addAttribute("journeys", journeys.findAll()) ; model
GetMapping(“/journes”)
没有被识别
@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());
}
}
最后一部分是travely.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>
这真的很令人沮丧,我无法参与到这项事业中来
感谢您的帮助。您是否尝试过直接使用URL?我怀疑它工作得很好,
这是一个输入错误还是您的旅程
方法作为控制器单独注释?(我同意@drekbour的观点)
<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>