mvc 中的m怎么写
我做的项目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;
}
}