带有胸腺胸膜双方结合的Springboot
我正在尝试将胸腺与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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
胸腺的工作方式是,它采用模板,注入模型并将其提供给客户端,这称为服务器端渲染。
当您更改输入字段中的值时,您正在更改客户端,并且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