带有胸腺胸膜双方结合的Springboot

发布于 2025-02-12 20:17:58 字数 736 浏览 1 评论 0原文

我正在尝试将胸腺与Springboot一起使用。但是有些问题发生了,我不是为什么。

这是我的代码:

@GetMapping
public String main(Model model) {

    Map<String, String> map = new HashMap<>();
    map.put("field1", "value1");
    map.put("field1", "value1");

    model.addAttribute("myMap", map);
    return "index";
}

这是html:

<div class="nav" th:each="myEntry:${myMap}">
     <label th:text="${myEntry.getKey()}"></label>
     <input th:value="${myEntry.getValue()}">
     <button class="btn" th:onclick="'javascript:trigger()'">Trigger</button>

</div>

如您在Java和HTML。I中所看到的那样,为模型设置了一个键值对,并将其用作标签,值作为输入。当我更改输入字段的值时。模型中的值(即myMap)不会改变。

有人知道为什么或如何?

I'm trying to use thymeleaf with springboot. but some problems happened and I don't why.

Here's my code:

@GetMapping
public String main(Model model) {

    Map<String, String> map = new HashMap<>();
    map.put("field1", "value1");
    map.put("field1", "value1");

    model.addAttribute("myMap", map);
    return "index";
}

and here's the html:

<div class="nav" th:each="myEntry:${myMap}">
     <label th:text="${myEntry.getKey()}"></label>
     <input th:value="${myEntry.getValue()}">
     <button class="btn" th:onclick="'javascript:trigger()'">Trigger</button>

</div>

As you can see in the java and html。I set a key-value pair for the model, and use it's key as a label, value as a input. When I change the value of the input field. The values(that is myMap) in the model don't change.

Anyone knows why or how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2025-02-19 20:17:59

胸腺的工作方式是,它采用模板,注入模型并将其提供给客户端,这称为服务器端渲染。

当您更改输入字段中的值时,您正在更改客户端,并且HTML完全与服务器端无关,因为所有后端都为您的页面服务。

如果您想要浏览器和服务器之间的来回通信,通常人们会使用Web插座。这是一个示例从Spring.io使用WebSockets

The way that thymeleaf works here is that it takes the template, injects the model and serves it to the client, this is called server side rendering.

When you change the value in the input field you are making changes client side and the HTML is not related to the server side at all, as all backend does is serves your page.

If you want a back and forth communication between browser and server typically people use web sockets. Here's an example from spring.io on using websockets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文