springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据

时间:2023-12-19 13:06:32

springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据

表单html:

                            <form class="form-horizontal form-material" th:object="${user}" th:action="@{/user/updateOneUserInfo}" method="post">
<input type="hidden" name="id" th:field="*{id}">
<div class="form-group">
<label class="col-md-12">姓 名</label>
<div class="col-md-12">
<input type="text" placeholder="Johnathan Doe" class="form-control form-control-line" th:field="*{userName}">
</div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">邮 箱</label>
<div class="col-md-12">
<input type="email" placeholder="johnathan@admin.com" th:field="*{email}" class="form-control form-control-line" name="example-email" id="example-email">
</div>
</div>
<div class="form-group">
<label class="col-md-12">电话号码</label>
<div class="col-md-12">
<input type="text" placeholder="123 456 7890" th:field="*{telephone}" class="form-control form-control-line">
</div>
</div>
<div class="form-group">
<label class="col-md-12">职 业</label>
<div class="col-md-12">
<input type="text" placeholder="" th:field="*{job}" class="form-control form-control-line">
</div>
</div>
<div class="form-group">
<label class="col-md-12">个人简介</label>
<div class="col-md-12">
<textarea rows="5" class="form-control form-control-line" th:field="*{shortMessage}"></textarea>
</div>
</div>
<!--地址暂未处理-->
<div class="form-group">
<label class="col-sm-12">选择所在地</label>
<div class="col-sm-12">
<div data-toggle="distpicker" class="row col-md-12">
<select class="col-md-4 form-control" data-province="北京市"></select>
<select class="col-md-4 form-control" data-city="北京城区"></select>
<select class="col-md-4 form-control" data-district="东城区"></select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12" style="text-align: center">
<button class="btn btn-success" type="submit">更新资料</button>
</div>
</div>
</form>

后台按照post的地址进行接收即可,需要注意的是,提交数据的时候,button或者input都设置成为submit,然后获取数据的时候用成th:field={*变量}的形式获取数据即可