gpt4 book ai didi

java - Spring mvc 无法在表单中使用 post 方法

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:58 25 4
gpt4 key购买 nike

当我开始编写应用程序时,提交了表单并且 createAnnotation 方法起作用了。现在不行了。为什么?顺便说一句,GET 方法在 Controller 中执行,而 POST 则不会。

@Controller
@RequestMapping("/annotation")
public class AnnotationController {

@RequestMapping(value = "/new", method = RequestMethod.POST)
public String createAnnotation(@ModelAttribute Annotation annotation, BindingResult result){
annotationService.create(annotation);
return "redirect:/annotation/annotations.htm";
}

}
<form action="${pageContext.request.contextPath}/annotation/new" method="post">
<div class="form-group">
<label for="text">Annotation name</label>
<input type="text" class="form-control" id="text" placeholder="Annotation name" name="name"/>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" placeholder="Date" name="date"/>
</div>
<div class="form-group">
<label for="comment">Description:</label>
<textarea class="form-control" rows="5" id="comment" name="description"></textarea>
</div>
<input type="hidden" name="profil.id" value="1"/>
<input type="submit" class="btn btn-default" value="Submit"/>
</form>

最佳答案

我不知道为什么,但是当我在表单标签中添加此代码时,所有都已修复

<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />

wTf???

关于java - Spring mvc 无法在表单中使用 post 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com