将Spring 3 MVC注释验证与Freemarker一起使用

问题描述

|| 我正在使用Spring 3 MVC注释验证。我知道如何在JSP中做到这一点(使用JSP中的
modelAttribute
属性),但是我不知道如何在Freemarker中应用这种数据绑定。 JSP等价示例
<c:url var=\"addUrl\" value=\"/admin/workerAdd\" />
<form:form modelAttribute=\"worker\" action=\"${addUrl}\" method=\"post\">
    <p>
 <form:label for=\"code\" path=\"code\">Code</form:label>
     <form:input path=\"code\" readonly=\"false\" />
    </p>
...
控制器示例:
@Controller
@RequestMapping(\"/admin/*\")
public class AdminController {    
    @Autowired
    private CommonService commonService;

    /**
     * For every request for this controller,this will 
     * create a person instance for the form.
     */
    @ModelAttribute
    public Worker newRequest(@RequestParam(required=false) String id) {
        return (id != null ? commonService.getWorkerById(id) : new Worker());
    }

    @RequestMapping(value=\"/workerAdd\",method=RequestMethod.POST)
    public final String performAddUser(@Valid Worker worker,BindingResult result) throws Exception {
        if (result.hasErrors()) {
            return null;
        }

            // Create the worker here.

        return \"redirect:/administration/manageUser\";
    }
现在,我想使用相同的控制器,但是视图由Freemarker(ftl)编写。我下面的freemarker中的数据绑定不起作用(这是可以理解的,因为它应该具有不同的语法)。我进行了一些研究,并了解了FTL中的命令对象,但我不明白这一点。我认为应该是类似的属性,告诉Spring进行绑定,但是我仍然找不到它。
<form id=\"worker\" modelAttribute=\"worker\" action=\"${rc.getContextUrl(\'/admin/workerAdd\')}\" method=\"post\" >          
            <div class=\"Entry\">
            <label for=\"code\">Code</label>
            <input type=\"text\" id=\"code\" name=\"code\" value=\"${worker.code}\" />
            </div>
有什么简单的方法可以使此批注验证方法(以及数据绑定)与FTL一起使用?任何帮助将不胜感激。 谢谢, 黄朗     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)