action、service、dao层建立:
1、action层:继承自 BaseAction
注意:(1)导入的service和声明的实体类或变量,均需要get和set才能获取到;
(2)实体类前不能加@Resource,否则会报错。
public class GenuineSerialNumberManagementAction extends BaseAction {
private static final long serialVersionUID = -3616113266159998137L;
@Resource
private GenuineSerialNumberManagementService genuineSerialNumberManagementService;
private GenuineSerialNumberManagement genuineSerialNumberManagement;
//与页面相关的都在此层设计
}
2、service层:通常包含2块:
一块声明service类,继承自 BaseService ,如下:action里面需要调用service层的类,均要在此先声明定义
public interface GenuineSerialNumberManagementService extends BaseService<GenuineSerialNumberManagement> {
public GenuineSerialNumberManagement queryBySoftDisplayName(String softDisplayName);
@Override
void save(GenuineSerialNumberManagement entity);
void createXML();
public String importTemplate(File file);
//action层里要调用service层的方法,均要在此先声明定义
}
另一块service实现类,继承自 BaseServiceImpl 和 GenuineSerialNumberManagementService ,service层定义的方法,均要在此实现类层进行方法实现。
@Service("genuineSerialNumberManagementService")
@Transactional
public class GenuineSerialNumberManagementServiceImpl extends BaseServiceImpl<GenuineSerialNumberManagement> implements GenuineSerialNumberManagementService {
protected GenuineSerialNumberManagementDao genuineSerialNumberManagementDao;
public GenuineSerialNumberManagementDao getGenuineSerialNumberManagementDao() {
return genuineSerialNumberManagementDao;
}
@Resource(name="genuineSerialNumberManagementDao")
public void setGenuineSerialNumberManagementDao(GenuineSerialNumberManagementDao genuineSerialNumberManagementDao) {
this.genuineSerialNumberManagementDao = genuineSerialNumberManagementDao;
this.baseDao = genuineSerialNumberManagementDao;
}
//service层定义的方法,均要在此实现类层进行方法实现
}
3、dao层:也分2块:此层是写与数据库进行交互的方法
一块dao类:继承自 BaseDao,在serviceImpl实现类层调用的与数据库交互的方法,均要在此层先声明定义
public interface GenuineSerialNumberManagementDao extends BaseDao<GenuineSerialNumberManagement> {
public GenuineSerialNumberManagement queryBySoftDisplayName(String softDisplayName);
@Override
void save(GenuineSerialNumberManagement entity);
List<GenuineSerialNumberManagement> queryByType(Integer type);
List<GenuineSerialNumberManagement> queryBySoftIdAndType(Integer softId, Integer type);
List<GenuineSerialNumberManagement> queryBySoftId(Integer softId);
// 在serviceImpl实现类层调用的与数据库交互的方法,均要在此层先声明定义
}
一块dao实现类:继承自BaseDaoImpl 和 GenuineSerialNumberManagementDao , dao层定义的方法,均要在此层进行方法实现
@Repository("genuineSerialNumberManagementDao")
public class GenuineSerialNumberManagementDaoImpl extends BaseDaoImpl<GenuineSerialNumberManagement> implements GenuineSerialNumberManagementDao {
@Override
public GenuineSerialNumberManagement queryBySoftDisplayName(String softDisplayName) {
return (GenuineSerialNumberManagement) getSession().createQuery(" from "+this.clazz.getName()+" this where this.softDisplayName=:softDisplayName ")
.setParameter("softDisplayName", softDisplayName)
.uniqueResult();
}
@Override
public void save(GenuineSerialNumberManagement entity) {
super.save(entity);
};
@SuppressWarnings("unchecked")
@Override
public List<GenuineSerialNumberManagement> queryBySoftIdAndType(Integer softId,Integer type) {
return this.getSession().createQuery(" FROM " + this.clazz.getName() + " this WHERE this.softId =(:softId) AND this.type =(:type)")
.setParameter("softId", softId)
.setParameter("type", type)
.list();
}
//dao层定义的方法,均要在此层进行方法实现
}