首页 > 解决方案 > 如何使用 Spring Boot 发送发布请求?

问题描述

我正在使用 POSTMAN 发送 post api 请求,它工作正常。我必须发送 JSON RAW

{
    "id": "232",
    "message": "elele",
    "authorName": "JK Rowling"
}

我得到了成功的回应。但我想从用户界面发送发布请求,但它不起作用。

这是 ThymeLeaf 处理错误:

"Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' 

这是它的html部分:

<form action="#" th:action="@{/api/v1/greetings}" th:object="${greeting}" method="post">
        <p>Message: <input type="text" th:field="*{message}" /></p>
        <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
    </form>

这是控制器代码:

@Controller
@RequestMapping(path = "/api/v1/greetings")
public class GreetingController {

    @ApiOperation(value = "Create Greeting", notes = "Create a greeting based on the given input")
    @PostMapping
    public ResponseEntity<GreetingResponse> create(@Valid @RequestBody GreetingRequest greetingRequest) {
    //
    }

这是课程:

public class Greeting {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@Column(name = "message")
String message;

@Column(name = "author_name")
String authorName;

我哪里错了?

标签: javaspring-bootthymeleaf

解决方案


推荐阅读