spring mvc和freemarker - 如何发表表格?

时间:2015-11-27 06:02:50

标签: forms spring-mvc freemarker

我不确定用spring和freemarker做简单的crud操作。这就是我试过的。

springTag.ftl

<!DOCTYPE html>

  <html xmlns:sec="http://www.springframework.org/security/tags" >

 <head>
 ......
 <#import "/spring.ftl" as spring />
 ..........

 <head>
  ......


 </head>

  <body>

  <@fragment.header/>


   <form action="/listController/springTag" method="post" >
    <@spring.bind "student" />
                            <table>
                                <tr>
                                    <td>Name:</td>
                                    <td><input path="student.name"  /></td>
                                </tr>

                                <tr>
                                    <td>Age:</td>
                                    <td><input path="student.age"  /></td>
                                </tr>

                                <tr>
                                    <td colspan="2">
                                        <input type="submit" value="Save Changes" />
                                    </td>
                                </tr>
                            </table>
                        </form>
                      ........................

                            </body>

如何获取控制器中的值?我已将模型属性指定为student。我是新手。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

我找到了答案。

<form action="/listController/springTag" method="post" >
                        <@spring.bind path= "student" />
                            <table>
                                <tr>
                                    <td>Name:</td>
                                    <td>  <@spring.formInput "student.name" /> </td>
                                </tr>

                                <tr>
                                    <td>Age:</td>
                                    <td><@spring.formInput "student.age" />
                                    <@spring.showErrors "student.age","error" /></td>
                                </tr>

                                <tr>
                                    <td colspan="2">
                                        <input type="submit" value="Save Changes" />
                                    </td>
                                </tr>
                            </table>
                        </form>

这是我所做的改变。