Q1。为什么它不转发到form.html
<a class="btn btn-primary btn-sm" href="form.html" th:href="@{/(form)}">Create Topic</a>
@GetMapping(params = "form")
public String createForm(@ModelAttribute Topic topic) {
return "redirect:/messages/form";
}
它返回字符串,而不是form.html
Q2。我该如何访问这些方法?
@RequestMapping(method=RequestMethod.PUT, value="/topics/{id}")
public void updateTopic(@RequestBody Topic topic, @PathVariable String id) {
topicService.updateTopic(id, topic);
}
@RequestMapping(method=RequestMethod.DELETE, value="/topics/{id}")
public void deleteTopic(@PathVariable String id) {
topicService.deleteTopic(id);
}
<a href="topic.html" th:href="@{'/topics/' + ${topic.id}}">delete</a>
<a href="form.html" th:href="@{'/topics/' + ${topic.id}}"> modify</a>
答案 0 :(得分:0)
您的问题1需要更多详细信息
您可以添加详细信息吗?你的应用程序代码中是否有一个URL /messages/form
: -
@GetMapping(params = "form")
public String createForm(@ModelAttribute Topic topic) {
return "redirect:/messages/form";
}
回答你的问题2: -
您不能在超链接中使用HTTP GET以外的任何内容来获取锚标记
要从超链接执行GET以外的任务,您可以为其他NON GET方法创建AJAX请求。
如下所示: -
<a href="topic.html" th:href="@{'/topics/' + ${topic.id}}" onClick="functionDelete(this)">delete</a>
<a href="form.html" th:href="@{'/topics/' + ${topic.id}}" onClick="functionModify(this)"> modify</a>
<script>
functionDelete(topic){
// ajax call to delete method, the url of HTTP type PUT
}
functionModify(topic){
// ajax call to delete method, the url of HTTP type PUT
}
</script>