一些springboot + thymeleaf + boostrap开发遇到的问题
插入、修改时:在form表单中,input不能使用th:value="*{orgCode}",会发生传值失败的情况,要使用th:field="*{orgCode}"
<form action="#" th:action="@{/policy/publish}" th:object="${policyPublishRequestDto}" th:method="post">
<br>
机构代码:<input type="text" th:field="*{orgCode}" id="orgCode"><br>
发布日期:<input type="date" th:field="*{publishDate}" id="publishDate" placeholder="格式: yyyy-MM-dd"><br>
发布人Id:<input type="text" th:field="*{publisherId}" id="publisherId"><br>
政策标题:<input type="text" th:field="*{policyTitle}" id="policyTitle"><br><br>
政策内容:<textarea th:field="*{policyContent}" id="policyContent" rows="8"></textarea><br><br>
文件路径:[[${relativePath}]]
<br><br>
<input type="submit" value="发布政策">
</form>
删除、修改操作,在java中使用@DeleteMapping和@PutMapping注解,但是form表单仅支持get、post方式提交,所以要处理Restful的delete、put请求的话,要多写一个input隐藏域,而且还要修改spring配置文件的内容
<form action="#" th:action="@{/policy/publish}" method="post" th:object="${policyPublishDetailDto}">
<input type="hidden" name="_method" value="PUT">
<input type="submit" value="确认修改">
</form>
spring:
mvc:
hiddenmethod:
filter:
enabled: true