Form parameter is null with Thymeleaf and Spring MVC

前端 未结 1 1681
暗喜
暗喜 2020-12-18 03:50

i\'m having a problem with Thymeleaf and Spring MVC.

I\'m following a tutorial from spring.io website http://spring.io/guides/gs/handling-form-submission/ and when I

相关标签:
1条回答
  • This is the expected behavior. You have the model in the response while getting to your greetings view, but as long as that http request/response is done, it doesn't exist anymore. You will hold the values in the <form> tag and you will need to provide these values upon form submit.

    Meaning, that if you want to send these values back you will need to add 2 hidden inputs to hold these two values.

    <form action="#" th:action="@{/greeting}" th:object="${greeting}" method="post">
        <p>Id: <input type="text" th:field="*{id}" /></p>
        <p>Message: <input type="text" th:field="*{content}" /></p>
        <input type="hidden" th:field="*{hour}" />
        <input type="hidden" th:field="*{longNumber}" />
        <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
    </form>
    
    0 讨论(0)
提交回复
热议问题