我正在构建一个SpringMVC项目,并且只是想对我的设计提供一些反馈。春季项目冗余类
目前我有以下的UserDAO
package org.myproj.com.dao;
import org.myproj.com.entity.User;
public interface UserDao {
public User getById(Long id);
}
这是通过到UserDAOImpl
package org.myproj.com.dao;
import org.myproj.com.entity.User;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository("userDao")
public class UserDaoImpl implements UserDao{
@Autowired
private SessionFactory sessionFactory;
public User getById(Long id) {
return (User) sessionFactory.getCurrentSession().get(User.class, id);
}
}
实现,那么我有一个服务层,UserService
package org.myproj.com.service;
import org.myproj.com.entity.User;
public interface UserService {
public User getById(Long id);
}
随着IMPL ,UserServiceImpl
package org.myproj.com.service;
import org.myproj.com.dao.UserDao;
import org.myproj.com.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
public UserServiceImpl() {
}
@Transactional
public User getById(Long id) {
return userDao.getById(id);
}
}
这然后通过我的servlet与...
@Autowired
private UserService userService;
User user = userService.getById(1L);
我不禁觉得我的道,我的服务被复制了很多访问。我正在考虑使用服务层来添加诸如角色等的东西,Dao执行业务逻辑。
您对这种设计有什么看法?可以接受吗?