屬性驅動 and 模型驅動
阿新 • • 發佈:2017-08-08
參數 ces over upd 實例 str ring new div
//1.創建一個UserBean public class User { private String username; private String pwd; public String getUsername() { return username; } public void setUsername(String username) { this.username = user name; } public String getPwd() { return pwd; }public void setPwd(String pwd) { this.pwd = pwd; } @Override public String toString() { return "User [username=" + username + ", pwd=" + pwd + "]"; } } public class UserAction1 { /* * 屬性驅動-1 * 創建對應的屬性,名稱和jsp頁面傳遞過來的參數名稱一致 * 創建對應屬性的get和set方法*/ private String username; private String pwd; public String add(){ System.out.println("賬號:" + username); System.out.println("密碼:" + pwd); return "success"; } public String getUsername() { return username; } public void setUsername(String username) {this.username = username; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } } /** * 屬性驅動-2 * 封裝為一個對象,jsp頁面參數需要將name屬性值設置為 【成員變 * 量.屬性名稱】的方式傳遞參數 * @author think * */ public class UserAction2 { private User user; public String save(){ System.out.println(user); return "success"; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } /** * 模型驅動 * 1.實現ModelDriven接口,泛型傳入的是接收的數據 * 2.創建成員變量,必須實例化model對象 * 3.實現getModel方法,返回model對象 * * @author think * */ public class UserAction3 implements ModelDriven<User>{ private User model = new User(); public String update(){ System.out.println(model); return "success"; } @Override public User getModel() { return model; } }
屬性驅動 and 模型驅動