我是靠谱客的博主 鳗鱼小天鹅,最近开发中收集的这篇文章主要介绍thymeleaf获取id值,如何设置thymeleaf th:来自其他变量的字段值,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I have a simple text input field where i have to set default value from one object and save its final value in other. The following code is not working.

type="text"

th:value="${client.name}" //this line is ignored

th:field="*{clientName}"/>

form is DTO object and client is Entity object from database.

What is the correct way to solve this situation?

By not working I mean - lets say that initial values are client.name="Foo" and form.clientName=null.

I need that input field display value is "Foo" and after form submission form.clientName value to become "Foo". But the input field displays nothing and on submission form.clientName value still is null;

If anyone is interested, solved this issue using following structure (found the answer in another question).

th:attr="value = ${client.name}"

解决方案

You could approach this method.

Instead of using th:field use html id & name. Set value using th:value

type="text"

th:value="${client.name}" id="clientName" name="clientName" />

Hope this will help you

最后

以上就是鳗鱼小天鹅为你收集整理的thymeleaf获取id值,如何设置thymeleaf th:来自其他变量的字段值的全部内容,希望文章能够帮你解决thymeleaf获取id值,如何设置thymeleaf th:来自其他变量的字段值所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部