0
我有一个弹簧启动应用程序,以及 我试图用POST方法下面的控制器发送对象:请求方法“POST”不支持
@PostMapping("/suggestevent")
public String receiveSuggestedEvent(@ModelAttribute SuggestedEvent event) {
return "redirect:/suggestEvent";
}
,但它与抱怨:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
那么,什么是错的?
更新: 我已经试过这一点,它也没有工作
@RequestMapping(value = "/suggestevent", method = RequestMethod.POST)
表单包含一些简单的inputes和选择,其工作原理基于Thyemeleaf。这里是我的形式:
<form th:action="@{/suggestevent}" method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text"
class="form-control" id="title" placeholder="Event title"
th:value="${event.title}"
name="title" required="required"/>
</div>
<div class="form-group">
<label for="mainFouce">Main Focus</label>
<input type="text"
class="form-control" id="Focus" placeholder="Focus"
th:value="${event.mainFouce}"
name="Focus" required="required"/>
</div>
Event Type
<div class="form-group">
<select class="form-control" name="type" th:value="${event.type}">
<option value="volvo">Party</option>
<option value="saab">Workshop</option>
<option value="fiat">Friendship</option>
</select>
</div>
<div class="form-group">
<label for="city">Area</label>
<input type="text"
class="form-control" id="area"
th:value="${event.area}"
placeholder="Berlin, Estonia ,or even Asia" name="area"
required="required"/>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea name="description" class="form-control"
th:value="${event.description}"
required="required" form="usrform"
placeholder="What makes it an special event?"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
的发送对象是:
@Entity
@Data
public class SuggestedEvent {
@Id
@GeneratedValue
Long id;
String title;
String mainFouce;
EventType type;
String area;
String description;
}
邮递员可以顺利到达控制器,但thyemeleaf抱怨!
可能有多种原因。你检查了[这些问题](https://stackoverflow.com/search?q=Request+method+%27POST%27+not+supported)?似乎有很多人有同样的问题。 – mumpitz
如果您使用CSRF保护,请添加输入字段:https://stackoverflow.com/questions/11145884/http-status-405-request-method-post-not-supported-spring-mvc – bphilipnyc