如何正确地向控制器发送参数? (Thymeleaf + Javascript)

问题描述 投票:1回答:1

我是Thymeleaf的初学者。我所知道的是“ Thymeleaf不是Javascript,而是在服务器上呈现的”这一事实。我一直在犯错误,因为我通常会像JavaScript一样尝试使用Thymeleaf。

HTML

   <form th:action="@{/user/sqlCode}" method="post">
        <button id="newDatabase"></button>
   </form>
   <textarea id="generatedSql" readonly></textarea>

Controller

@PostMapping(path = { "/user/sqlCode" })
public String createSchema(@RequestParam(???) String tmp) {
    String finallyMyValue = tmp;
    //STOP  I want to have data from generatedSql in this moment, in that variable "finallyMyValue"
    ...
}

@ @ @MISSION @1.单击按钮((id:newDatabase)2.从textarea (id:generateSql)获取数据3.将带有该数据的值发送到控制器4.开心一点:)@@ MISSION @

我尝试了很多事情,但仅使用Javascript。情况总是一样,JavaScript完全在Thymeleaf之前执行,最后我无法正确读取数据...我尝试了这种情况:

  1. 单击按钮((id:newDatabase)
  2. 从文本区域获取数据((id:generateSql) 使用JavaScript
  3. 将数据插入输入标签使用JavaScript]的变量name>
  4. 将变量name发送到控制器。
  5. 而且这里我总是得到NULL或错误404
  6. [我的方法失败的屏幕截图,在断点处以null结尾:enter image description here

有人可以帮忙吗?

我是Thymeleaf的初学者。我所知道的是“ Thymeleaf不是Javascript,而是在服务器上呈现的”这一事实。我一直在犯错误,因为我通常试图使用Thymeleaf a ...

javascript jquery html spring thymeleaf
1个回答
1
投票

我认为您应该尝试将Javascript与Ajax结合使用:

© www.soinside.com 2019 - 2024. All rights reserved.