首页 > 解决方案 > 如何使用 Spring MVC 和 Pebble 模板引擎将 Java 对象绑定到 HTML 表单

问题描述

我无法让Pebble模板引擎在 HTTP GET 请求中以 HTML 形式显示 Java 对象值。

在 Pebble 模板中,我有一个这样的表单。

<form name="userDetailsForm" action="/update-details" method="post">
    <label>Email Address: </label>
    <input type="text" id="emailAddress" name="emailAddress">
</form>

在 Spring MVC 中我有

@GetMapping("/update-details")
public ModelAndView showUpdateDetails()
{
    UserDetailsForm form = new UserDetailsForm();
    form.setEmailAddress("example@example.com");
    return new ModelAndView("update_details_template", "userDetailsForm", form);
}

当我在浏览器中加载页面时,电子邮件输入字段为空白。我希望用“example@example.com”填充电子邮件输入字段。我怎样才能做到这一点?Pebble 是否能够在 HTTP Get 请求中将 Java 对象绑定到 HTML 表单?

标签: javahtmlspring-mvcmodelandviewpebble

解决方案


推荐阅读