我不确定用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
。我是新手。有人可以帮忙吗?
答案 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>
这是我所做的改变。