SpringMVC form标签
@RequiresPermissions(value={"people:student:view","people:student:add","people:student:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(Student student, Model model) {
student.setName("张小三");
student.setAge("23");
model.addAttribute("student", student);
return "modules/people/student";
}
@RequiresPermissions(value={"people:student:view","people:student:add","people:student:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(@ModelAttribute("student") Student student, Model model) {
student.setName("张小三");
student.setAge("23");
return "modules/people/student";
}
@RequiresPermissions(value={"people:student:view","people:student:add","people:student:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(@ModelAttribute("student") Student student, Model model) {
student.setName("张小三");
student.setAge("23");
model.addAttribute("student", student);
return "modules/people/student";
}
@ModelAttribute("student")这个stu是<form:form modelAttribute='student'>中的student.
<form:form action="/student/list.do" method="post" modelAttribute="student">
<table>
<tr>
<td>
<form:input path="name"/>
</td>
<td>
<form:input path="age"/>
</td>
</tr>
</table>
</form:form>
其它常见标签使用
Springform表单标签:form:input 、form:password、form:hidden、form:textarea:对应HTML表单的Text、password、hidden、textarea标签
form:radiobutton:单选框组建标签,对那个表单bean对应的属性和value值相等时,单选框被选中。
form:radiobuttons:单选框组件标签,用于构造多个单选框
-items:可以是一个list、String[]或者map
-itemValue:指定radio的value值。可以是集合中的bean的一个属性值
-itemLabel:指定radio的label值
-delimiter:多个单选框可以通过delimiter指定分割符
form:checkbox:复选框组件。用户构造单个复选框
form:checkboxs:用户构造多个复选框。使用方式同form:radiobuttons标签
form:select:用于构造下拉框组件,使用方式等同于form:radiobuttons标签
form:option :下拉框选项组件标签。使用方式等同于form:radiobuttons标签
from:errors:显示表单组件或数据校验所对应的错误
<form:form action="addUser" method="POST" modelAttribute="user">
id:<form:input path="id"/><br>
username:<form:input path="name" /><br>
pwd:<form:password path="pwd" /><br>
email:<form:input path="email" /><br>
department:<form:select path="department.id" items="${departments}"itemLabel="name" itemValue="id"></form:select>
<%
HashMap<String, String> sex = new HashMap<String, String>();
sex.put("0", "女");
sex.put("1", "男");
request.setAttribute("sex", sex);
%>
sex:<form:radiobuttons path="sex" items="${sex}" /><br>
<input type="submit" value="submit">
</form:form>
SpringMVC form标签
最新推荐文章于 2024-02-21 15:43:32 发布