SpringMVC's form: the use of form forms

  Why use SpringMVC's form: form form, there are two reasons: one is to complete the development of the form more quickly, for example, it will do the work for you, such as changing the data type, that you need to do yourself. The second is to be able to implement form echo more conveniently.
First, add such a line at the top to introduce the form:form class library.
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

The rest of the page is a simple form: the form form. Write code explanations directly into comments.

<!-- Similar to an ordinary form, where modelAttribute is used to bind a class; that is, the corresponding entity class after the form is submitted. -->
		<form:form action="addSto" method="post" modelAttribute="storageInformation">
			<!-- This format is just adding a form: in front of the common label, and then the path attribute should correspond to the corresponding attribute of the binding class corresponding to this note; the use of other notes below is similar to this, and no additional explanation is required. -->
			<form:input path="teacherId" name="teacherId" value="教师编号" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '教师编号';}"/>
			<form:input path="subjectId" name="subjectId" value="科目编号 " onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '科目编号';}"/>
			<form:input path="storageName"  name="storageName" value="名称" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '名称';}"/>
			<form:radiobutton path="category" name="category" value="0" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '类别';}" />科目共享 
			<form:radiobutton path="category" name="category" value="1" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '类别';}" />个人独有
			<br>
			<div class="forgot">
				
		    	<input type="submit" value="创建" >
		    </div>
		</form:form>


The bound model attribute can be specified through the modelAttribute attribute. If this attribute is not specified, the form bean of the command is read from the request domain object by default. If the property value does not exist either, an error occurs.
One last thing to note is that if you jump from a page to a jsp page of a binding class, you need to provide it with a form: the object of the binding class corresponding to the form. (Not sure if this is accurate). The jump logic in the background can be written like this:
StorageInformation storageInformation= new StorageInformation();
		return new ModelAndView("creat_storage").addObject(storageInformation);


That is to provide it with an empty binding class object, so as to avoid the above problems.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326692449&siteId=291194637