一、dao层
package com.csair.dao.impl;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;
import com.csair.dao.UserDao;
import com.csair.domain.User;
@Service("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
private Logger log = Logger.getLogger(this.getClass());
public int save(User user) {
log.info("save.....dao层。。。");
this.getHibernateTemplate().save(user);
return 0;
}
public User findOne(int id) {
return this.getHibernateTemplate().get(User.class, id);
}
public void delete(User user) {
this.getHibernateTemplate().delete(user);
}
public void update(User user) {
this.getHibernateTemplate().update(user);
}
public List<User> findList(User user) {
// TODO Auto-generated method stub
return null;
}
}
二、service层
package com.csair.service.impl;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.csair.dao.UserDao;
import com.csair.domain.User;
import com.csair.service.UserService;
@Service("userService")
public class UserServiceImpl implements UserService{
private Logger log = Logger.getLogger(this.getClass());
@Autowired
private UserDao userDao;
public int saveUser(User user) {
log.info("saveUser....业务逻辑层。。。。。");
userDao.save(user);
return 0;
}
public User findOne(int id) {
try{
return userDao.findOne(id);
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
public void delete(User user) {
userDao.delete(user);
}
public void update(User user) {
userDao.update(user);
}
public List<User> findList(User user) {
// TODO Auto-generated method stub
return null;
}
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
}
三、action层
package com.csair.action;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.csair.domain.User;
import com.csair.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Logger log = Logger.getLogger(this.getClass());
@Autowired
private UserService userService;
private User user;
public String login() {
System.out.println("username---" + user.getUsername());
System.out.println("password---" + user.getPassword());
log.info("验证登陆");
try {
// userService.saveUser(user);
User user = userService.findOne(7);
log.info("内容:" + user.toString());
// user.setUsername("hello");
// userService.update(user);
// userService.delete(user);
} catch(Exception e) {
e.printStackTrace();
}
return "login";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}