java - 前往铭文页面
问题描述
我在按 id 加载页面时遇到问题。我在 Spring 中创建简单的论坛,当我创建主题时,我得到了这样的页面 /topic/10(10 是 id 主题),接下来我想为这个主题添加题词,所以点击按钮后提交应该是 /inscription/topic/ 10(10 是 id 主题)。现在是问题所在,当我单击按钮时出现错误 405,但是当我拿起这一行并手写或复制地址并再次粘贴时,我得到了题词页面。问题出在哪里?它可以是百里香或春季请求?代码如下
@Controller
@RequestMapping("/inscription/")
public class InscriptionController {
private InscriptionService inscriptionService;
private TopicService topicService;
@Autowired
private InscriptionController(InscriptionService inscriptionService, TopicService topicService) {
this.inscriptionService = inscriptionService;
this.topicService = topicService;
}
@GetMapping("topic/{id}")
public String in2(@ModelAttribute("inscription") Inscription inscription, @PathVariable Long id, Model model) {
Topic topic = topicService.findOne(id);
model.addAttribute("inscription", inscription);
return "inscription";
}
Thymeleaf - 当我按下按钮时,新消息应该转到题字/主题/id
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Create new topic</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-light" style="background-color: #969bd9;">
<span class="navbar-brand">Create new topic</span>
</nav>
<div class = "container">
<div class = "row">
<div class = "col-md6 col-md-offset-3">
<form th:action="@{/inscription/topic/{id}(id = ${topic.id})}" th:object="${inscription}" method="post">
<h5>
<a th:href="@{/topic/{id}(id = topic.id)}"></a>
<span th:text="${topic.title}"></span>
</h5>
<div class="col s10">
<div class="row">
<div class="col s11">
Stworzony
<p th:text="${topic.createdAt} ? ${#calendars.format(topic.createdAt, 'HH:mm dd MMMM yyyy')}"></p>
<p th:utext="${#strings.replace(topic.text,T(java.lang.System).getProperty('line.separator'),'<br />')}"></p>
<div class="divider"></div>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">New message</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
解决方案
405 错误表示“方法不允许”。当您单击submit
按钮时,您form
将执行该POST
方法,该方法在您的控制器中没有相应的映射。您应该将POST
映射添加到您的控制器或将form
方法更改为GET
.
推荐阅读
- angular - 到 ContentChildren 的角度绑定宽度
- ruby-on-rails - 在 Rails 中添加属性以选择字段
- javascript - 反应选择元素值是将状态设置为先前选择的选项值吗?
- php - 每个 PHP,使用特定键的值
- python-3.x - 使用三元运算符过滤字符串
- reactjs - 在单个管道中进行多次扫描所需的步骤
- ruby-on-rails - 等效于 as: json 在 ruby on rails 中执行调用时
- ggplot2 - 多面面板上的 geom_text() 会导致符号映射发生变化
- assembly - 如何在每次循环迭代时将变量增加 0.321 - x86 程序集
- java - sendkeys(keys.Down) 和 sendkeys(keys.Arrow_Down) 之间的区别