ssi框架学习总结(mvc三层架构)(3)

RegisterAction.java:

package com.broada.demo.action; /** * @author smm */ import com.broada.demo.entity.User; import com.broada.demo.service.UserDaoServiceInter; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private static final long serialVersionUID = 1L; private UserDaoServiceInter userdaoServiceInter; public UserDaoServiceInter getUserdaoServiceInter() { return userdaoServiceInter; } public void setUserdaoServiceInter(UserDaoServiceInter userdaoServiceInter) { this.userdaoServiceInter = userdaoServiceInter; } private String name; //用户名 private String password; //密码 private String username; //昵称 private String address; //地址 public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String addUser() { System.out.println("添加成功!"); User user = new User(); String name = this.name; String password = this.password; String username = this.username; String address = this.address; user.setName(name); user.setPassword(password); user.setUsername(username); user.setAddress(address); boolean b = userdaoServiceInter.insertUser(user); if (b==true) { return SUCCESS; } else return INPUT; } public String loginUser(){ System.out.println("登陆======="); String name = this.name; String password = this.password; User user = userdaoServiceInter.querybyname(name); if(user != null && password.equals(user.getPassword())){ return SUCCESS; } else return ERROR; } }

UserDao.java

package com.broada.demo.dao; /** * @author smm */ import java.util.List; import com.broada.demo.entity.User; public interface UserDao { /** * 用户注册 * @param user * @return */ public boolean insertUser(User user); /** * 根据用户名获取用户信息 * @param name * @return */ public User queryByname(String name); }

UserDaoImpl.java

package com.broada.demo.daoImpl; /** * @author smm */ import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; import com.broada.demo.dao.UserDao; import com.broada.demo.entity.User; public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao{ @Override public boolean insertUser(User user) { try { getSqlMapClientTemplate().insert("insertUser", user); return true; } catch (Exception e) { e.printStackTrace(); return false; } } @Override public User queryByname(String name) { // TODO Auto-generated method stub try { User user =(User) getSqlMapClientTemplate().queryForObject("selsectUser", name); return user; } catch (Exception e) { e.printStackTrace(); return null; } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfzsg.html