4.4.1 创建一个实体类
编写并创建一个Java实体类,并重写了类的“toString()
”方法:
package com.marshal.springmvc.entity;
public class Marshal {
private String userName;
private String password;
private String name;
private String sex;
private String nativePlace;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getNativePlace() {
return nativePlace;
}
public void setNativePlace(String nativePlace) {
this.nativePlace = nativePlace;
}
@Override
public String toString() {
return "Marshal{" +
"userName='" + userName + '\'' +
", password='" + password + '\'' +
", name='" + name + '\'' +
", sex='" + sex + '\'' +
", nativePlace='" + nativePlace + '\'' +
'}';
}
}
4.4.2 编写提交页面
首先需要编写一个提交页面,并页面中所有提交参数的名称均与实体类的属性名称相同:
4.4.3 后台Controller
后台的Controller类的处理方法参数为实体类对象:
4.4.4 编写跳转成功页面
在工程的“web
”目录下编写创建跳转成功页面:
4.4.5 测试运行结果
启动Tomcat服务并进行浏览器中填写正确的访问地址:
页面跳转结果:
控制台打印输出: