我有这个表格:
<form action="/my-path" method="post">
<div class="form-group">
<label for="domain">Domain</label>
<input class="form-control" id="domain" type="text" value="" name="domain">
<label for="color">Color</label>
<input class="form-control" id="color" type="text" value="" name="color">
</div>
<button class="btn btn-primary" type="submit">Filter</button>
</form>
我试图在 Spring MVC 中处理:
@PostMapping(
path = ["/my-path"],
produces = [MediaType.TEXT_HTML_VALUE])
public ResponseEntity<String> doSomething(ModelMap map) {
// ...
}
但我就是无法正常工作,POST即使我用数据填写表格并提交,我也看不到任何数据。
我尝试将值绑定到我自己的 dto:
@PostMapping(
path = ["/my-path"],
produces = [MediaType.TEXT_HTML_VALUE])
public ResponseEntity<String> doSomething(@RequestBody MyDto dto) {
// ...
}
但在这种情况下,我得到一个异常,因为该方法不受支持(url 编码形式)。我在这里不知所措,我尝试了 10 种不同的方法来从请求中获取表单数据,但它不起作用,我要么得到异常,要么根本没有得到任何数据。
如何使这个非常基本的用例与 Spring Boot 一起使用?
慕后森
相关分类