mvc 中的m怎么写

sun_317 2008-09-03 06:03:18
我做的项目Struts2+hibernate 老是出现action调用dao:是不是我没有mod层,若是请问如何写,谢谢

service 如下:
public Users chickLogin(String email, String password, boolean chikemail)
throws Exception {
Transaction tx = null;
Users user = null;
Date d = null;
try {
UserDao userDao = (UserDao) DaoFactory.getInstance().getDao(
"userDaoImp");
Session session = HibernateUtil.getSession();
tx = session.beginTransaction();
if (chikemail) {
user = userDao.chickEmail(session, email);
} else {
user = userDao.chickUserName(session, email);
}
if (user != null) {
d = user.getLastLoginTime();
if (user.getUserPassword().equalsIgnoreCase(
Md5.getMd5(password))) {
user.setIntegral(user.getIntegral() + 1);
user.setLastLoginTime(new Date());
userDao.update(session, user);
}
}

tx.commit();
if (user != null) {
user.setLastLoginTime(d);
}
session.close();
} catch (Exception e) {
System.err.println("Userservice的 chickLogin 方法有错");
tx.rollback();
e.printStackTrace();
throw e;
}
return user;
}
action 如下:

public class UserLoginAction extends ActionSupport {


private Users users = null;



public Users getUsers() {
return users;
}


@SuppressWarnings("unchecked")
public String startlogin() throws Exception {
System.err.println("用户登陆运行了");
UserService userService = (UserService) ServiceFactory.getInstance()
.getservice("userServiceImp");
String email = "\\w+(\\.\\w+)*@\\w+(\\.\\w+)+";// 判断email的表达试
if (this.username.matches(email)) {
this.users = userService.chickLogin(this.username, this.password,
true);

} else {

this.users = userService.chickLogin(this.username, this.password,
false);

}
if (null == this.users) {
this.addFieldError("username", "您输入的电子邮件(用户名)不正确!");
return INPUT;
} else if (!users.getUserPassword().equalsIgnoreCase(
Md5.getMd5(this.password))) {
this.addFieldError("username", "您输入的密码不正确!");
return INPUT;
}
System.err.println(this.users.getLastLoginTime());
Map<String, String> session = ActionContext.getContext().getSession();
session.put("USER_NAME", this.username);
session.put("USER_PASSWORD", this.password);
return SUCCESS;
}
}
...全文
143 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧