百里香的名字字段值

时间:2016-10-03 09:22:29

标签: java spring-mvc thymeleaf

我想将此代码转换为模板,我可以通过传递类似字段的名称来包含该模板:

<div th:object="${form}">
  <div th:replace="'templates/fields' :: input_text (fieldName='user.userName')" />
</div>

<th:block th:fragment="input_text"> 
    <input class="form-control"
           type="text"
           th:field="*{fieldName}"/>
</th:block>

除非我改变,否则上面的代码不起作用  th:field="*{fieldName}"th:field="*{__${fieldName}__}"

如果不使用预处理,有没有办法做到这一点?

我实际上需要像Fields.getValue(String fieldName);

这样的东西

@Controller:

@RequestMapping(value = "/test", method = RequestMethod.GET)
  public String test(@ModelAttribute("form") TestForm form) {
    return "test"
  }

@RequestMapping(value = "/test", method = RequestMethod.POST)
  public String test(@Valid @ModelAttribute("form") TestForm form, BindingResult bindingResult) {
    return "test_success"
  }

public class TestForm implements Serializable {

  private static final long serialVersionUID = 123L;

  private String something;

  private String somethingElse;

  // ...
}

0 个答案:

没有答案