欢迎访问我的个人网站==》 jiashubing.cn

thymeleaf+springmvc 前端跳转到一个新的页面,并且传递一个参数

错误写法

<form id="printPdfForm" th:action="@{/forum/topicToPdf(topicId=${topic.id})}"></form>
$("#printPdfForm").submit();
 
<form id="printPdfForm" th:action="@{/forum/topicToPdf(topicId=${topic.id})}" target="_blank"></form>
 
这样写不对
只能变成http://localhost:8080/test/forum/details?
 

正确写法

用form 表单里的input 来传递参数
<form id="printPdfForm" th:action="@{/forum/topicToPdf}" method="post" target="_blank">
  <input type="hidden" name="topicId" th:value="${topic.id}"/>
</form>
http://localhost:8080/test/forum/details?id=44
 
可以不要  target="_blank"
 
原创文章,欢迎转载,转载请注明出处!
posted @ 2023-04-26 17:02  贾树丙  阅读(132)  评论(0编辑  收藏  举报