• 项目笔记:分层模型建立


    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层定义的方法,均要在此层进行方法实现
    }
     
  • 相关阅读:
    Uploadify v3.2.1 上传图片并预览
    mybatis批量操作
    500 拦截错误输出
    jsnop
    java目录
    设置360调用样式 IE调用样式
    Spring加载resource时classpath*:与classpath:的区别
    context:annotation-config 与context:component-scan
    Andriod调用http请求
    JDK环境变量
  • 原文地址:https://www.cnblogs.com/goloving/p/7491584.html
Copyright © 2020-2023  润新知