我对前端开发非常陌生。我有一个简单的 Web 应用程序,您可以在其中提交表单,并且我希望能够在 REST 端点中获取表单数据。我正在使用包含 Spring MVC 的 Spring boot。
HTML:
<div class="modal-header modal-header-info">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title">Add Entity</h4>
</div>
<div class="modal-body">
<form role="form" method="post" action="/createEntity">
<div class="form-group">
<label for="name">Name:</label> <input type="text"
class="form-control" id="name">
</div>
<button type="submit" class="btn btn-info">Submit</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
爪哇:
@RequestMapping(value = "/createEntity", method = RequestMethod.POST)
public void createEntity(@RequestBody String payload) {
System.out.println("Hello world!");
System.out.println(payload);
}
Run Code Online (Sandbox Code Playgroud)
我得到这个错误:
Failed to read HTTP message:
org.springframework.http.converter.HttpMessageNotReadableException:
Required request body is missing: public void main.java.info.spring.data.neo4j.controllers.CreateEntityController.createEntity(java.lang.String)
Run Code Online (Sandbox Code Playgroud)
如何从表单中获取“名称”值?如果我取出 @RequestBody 部分,则会打印出“hello world”属性。 …