@Component("user") @Scope("prototype") public class UserAction extends ActionSupport implements ModelDriven { private UserRegisterInfo info = new UserRegisterInfo(); private UserManager um; private List<User> users; public UserManager getUm() { return um; } @Resource(name="userManager") public void setUm(UserManager um) { this.um = um; } @Override public String execute() throws Exception { User u = new User(); u.setUsername(info.getUsername()); u.setPassword(info.getPassword()); if(um.exists(u)) { return "fail"; } um.add(u); return "success"; } public UserRegisterInfo getInfo() { return info; } public void setInfo(UserRegisterInfo info) { this.info = info; } //@Override public Object getModel() { return info; } public String list() { this.users = this.um.getUsers(); return "list"; } public List<User> getUsers() { return users; } public void setUsers(List<User> users) { this.users = users; } }
实现
implements ModelDriven该接口,在jsp页面中可以不用加xxx.username,直接写username即可
时间: 2024-10-13 20:23:28