Java 如何从thymeleaf文本框调用具有两个参数的构造函数?

Java 如何从thymeleaf文本框调用具有两个参数的构造函数?,java,spring,thymeleaf,Java,Spring,Thymeleaf,我有一个文本字段 <input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/> 使用上面的文本框,只调用第一个构造函数!我如何调用具有两个参数的构造函数,以及如何将区域设置传递给它?在您的位置,我将使用表单 测试表格: public class TestForm { private String name; private String local

我有一个文本字段

<input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>

使用上面的文本框,只调用第一个构造函数!我如何调用具有两个参数的构造函数,以及如何将区域设置传递给它?

在您的位置,我将使用表单

测试表格:

public class TestForm {

    private String name;
    private String locale;

    public TestForm() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    @Override
    public String toString() {
        return "TestForm [name=" + name + ", locale=" + locale + "]";
    }

}
控制器:

@RequestMapping(value = "/test", method = GET)
public String test(final ModelMap modelMap) {
    modelMap.put("testForm", new TestForm());
return "/test";
}

@RequestMapping(value = "/test", method = POST)
public String posttest(@ModelAttribute("testForm") final TestForm testForm) {
    System.out.println(testForm);
return "redirect:/somewhere/else";
}
test.html:

    <form th:object="${testForm}" method="post">
        <input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>
        <input type="text" class="form-control" id="locale" th:value="*{locale}" th:field="*{locale}"/>

        <button type="submit">Save</button>
    </form>

拯救
    <form th:object="${testForm}" method="post">
        <input type="text" class="form-control" id="name" th:value="*{name}" th:field="*{name}"/>
        <input type="text" class="form-control" id="locale" th:value="*{locale}" th:field="*{locale}"/>

        <button type="submit">Save</button>
    </form>