Java 进入题字页
我对id加载页面有问题。我在春季创建了一个简单的论坛,当我创建主题时,我得到了这样的页面/topic/10(10是id主题),接下来我想在这个主题中添加题词,所以在点击按钮后提交应该是/dentitle/topic/10(10是id主题)。现在的问题是,当我点击按钮,我得到了错误405,但当我采取这一行,手写或复制地址,并粘贴它再次,然后我得到了题字页。问题在哪里?它可以是thymeleaf或spring请求? 代码如下Java 进入题字页,java,spring,post,thymeleaf,Java,Spring,Post,Thymeleaf,我对id加载页面有问题。我在春季创建了一个简单的论坛,当我创建主题时,我得到了这样的页面/topic/10(10是id主题),接下来我想在这个主题中添加题词,所以在点击按钮后提交应该是/dentitle/topic/10(10是id主题)。现在的问题是,当我点击按钮,我得到了错误405,但当我采取这一行,手写或复制地址,并粘贴它再次,然后我得到了题字页。问题在哪里?它可以是thymeleaf或spring请求? 代码如下 @Controller @RequestMapping("/in
@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
按钮时,您的表单将执行POST
方法,该方法在控制器中没有相应的映射。您应该将POST
映射添加到控制器中,或者将form
方法更改为GET