「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原理及配置詳解


分享到:


相關文章: