2015-10-27 75 views
1

当我开始编写应用程序,表单submited和createAnnotation方法工作。现在它不起作用。为什么? 通过GET方法在控制器中执行的方式,POST不。弹簧mvc不工作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> 
+0

因此在URL中这个地址http:// localhost:8012/test/annotation/new和empy页面在浏览器中 –

+0

你能检查什么是记录的消息。另外尝试从参数中删除BindingResult。 –

+0

尝试将“$ {pageContext.re ......”更改为“新” –

回答

0

我不知道为什么,但是当我已在表单标签的代码,所有固定

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

跆拳道???

+0

今天我有这个问题。我可以向你解释它是什么,如果是真的 – GermanSevostyanov