「Spring」Spring MVC原理及配置详解

创建用户

tabindex="1">

tabindex="2">

tabindex="3">

id="submit" type="submit" tabindex="5" value="创建">

detail.jsp

pageEncoding="UTF-8"%>

Insert title here

创建成功

详情:

姓名:${user.name}
年龄:${user.age}
密码:${user.pwd}

UserController.java

package com.zjn.controller;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import com.zjn.entity.User;

/**

* 用户管理

*

* @author zjn

*/

@Controller

public class UserController {

@RequestMapping("")

public String Create(Model model) {

return "create";

}

@RequestMapping("/save")

public String Save(@ModelAttribute("form") User user, Model model) { // user:视图层传给控制层的表单对象;model:控制层返回给视图层的对象

model.addAttribute("user", user);

return "detail";

}

}

User.java

package com.zjn.entity;

import java.io.Serializable;

import java.util.Date;

public class User implements Serializable {

/**

* @author zjn

*/

private static final long serialVersionUID = 1L;

private Integer id; // id

private String name; // name

private String pwd; // pwd

private Integer age; // age

private Date creatTime; // creatTime

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPwd() {

return pwd;

}

public void setPwd(String pwd) {

this.pwd = pwd;

}

public Integer getAge() {

return age;

}

public void setAge(Integer age) {

this.age = age;

}

public Date getCreatTime() {

return creatTime;

}

public void setCreatTime(Date creatTime) {

this.creatTime = creatTime;

}

}

(4)运行结果

初始页面:

「Spring」Spring MVC原理及配置详解

输入参数:

「Spring」Spring MVC原理及配置详解

点击创建:

「Spring」Spring MVC原理及配置详解

「Spring」Spring MVC原理及配置详解


分享到:


相關文章: