`
everlxq
  • 浏览: 110149 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

BaseService BaseServiceImpl

 
阅读更多
package com.web.base;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.poi.ss.usermodel.Cell;
import org.hibernate.Session;

/**
 * Generic Manager that talks to GenericDao to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) managers
 * for your domain objects.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public interface BaseService<T, PK extends Serializable> {

    /**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     * @return List of populated objects
     */
    List<T> getAll();

    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     *
     * @param id the identifier (primary key) of the object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id);

    /**
     * Checks for existence of an object of type T using the id arg.
     * @param id the identifier (primary key) of the object to get
     * @return - true if it exists, false if it doesn't
     */
    boolean exists(PK id);

    /**
     * Generic method to save an object - handles both update and insert.
     * @param object the object to save
     * @return the updated object
     */
    T save(T object);

    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    void remove(PK id);
    
    public void removes(PK[] ids);
    
    void remove1(PK id);
    
    public void removes1(PK[] ids);
    public List<T> getByHql(String hql,Object[] objs);
    
    public List getAllByHql(String hql,Object[] objs);
	
	public void updateQuery(final String hql,final Map map);

	public List<T> getPageData(String hql, Map map, int pageIndex, int pageSize);
	
	public List<T> getPageData(String hql, Map map);

	public int getPageSize(String hql, Map map);
	
	public BigDecimal getTotalCount(String hql, Map map);
	
	public String getCellValue(Cell cell);

	public void removes2(PK[] ids, Map session);
}




package com.web.base;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;

public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {
    /**
     * Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * GenericDao instance, set by constructor of this class
     */
    protected BaseDao<T, PK> baseDao;

    /**
     * Public constructor for creating a new GenericManagerImpl.
     * @param genericDao the GenericDao to use for persistence
     */
    public BaseServiceImpl(final BaseDao<T, PK> baseDao) {
        this.baseDao = baseDao;
    }

    /**
     * {@inheritDoc}
     */
    public List<T> getAll() {
        return baseDao.getAll();
    }

    /**
     * {@inheritDoc}
     */
    public T get(PK id) {
        return baseDao.get(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean exists(PK id) {
        return baseDao.exists(id);
    }

    /**
     * {@inheritDoc}
     */
    public T save(T object) {
        return baseDao.save(object);
    }

    /**
     * {@inheritDoc}
     */
    public void remove(PK id) {
    	baseDao.remove1(id);
    }
    
    public void removes(PK[] ids){
    	baseDao.removes1(ids);
    }
    
    public void remove1(PK id) {
    	baseDao.remove(id);
    }
    
    public void removes1(PK[] ids){
    	baseDao.removes(ids);
    }
	
	public List<T> getPageData(String hql, Map map, int pageIndex, int pageSize) {
		return baseDao.getPageData(hql, map, pageIndex, pageSize);
	}
	
	public List<T> getPageData(String hql, Map map) {
		return baseDao.getPageData(hql, map);
	}

	public int getPageSize(String hql, Map map) {
		return baseDao.getPageSize(hql,map);
	}
	
	public BigDecimal getTotalCount(String hql, Map map){
		return baseDao.getTotalCount(hql,map);
	}

	public List<T> getByHql(String hql, Object[] objs) {
		return baseDao.getByHql(hql, objs);
	}

	public void updateQuery(String hql, Map map) {
		baseDao.updateQuery(hql, map);		
	}

	public List getAllByHql(String hql, Object[] objs) {
		return baseDao.getAllByHql(hql, objs);
	}
	
	public String getCellValue(Cell cell){
		if(cell!=null){
			if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC)
				return String.valueOf(cell.getNumericCellValue());
			else return cell.getRichStringCellValue().toString().trim();
		}else return null;		
	}

	public void removes2(PK[] ids,Map session) {
		baseDao.removes2(ids,session);
	}


}

分享到:
评论

相关推荐

    springMVC+Mybatis封装整合

    springMVC+Mybatis封装整合:整合搭建已经完成不再述,本框架特色主要针对Mybatis框架BaseDao,BaseService,BaseServiceImpl封装,有点贵,本人也是循序见进到这一步,花了将近一个月时间,之前发布版本可以不下载...

    SSM代码生成工具/改进版Mybatis代码生成工具

    在标签中,请指定 name 为baseMapper,baseService,baseServiceImpl,baseController 的value属性(超类位置). 2.本项目中的basic包下可见超类的具体在实现代码.复制粘贴即可. 本应用鼓励使用超类,由JVM实现类型判断,...

    SSH框架网上商城项目第2战之基本增删查改、Service和Action的抽取

    为了提高代码的可重用性和模块化,我们抽取了一个基础Service接口`BaseService`和它的实现类`BaseServiceImpl`。`BaseService`通常包含一些通用的方法,例如事务管理、数据验证等。`BaseServiceImpl`则提供了与数据...

    spring注解

    public class BaseServiceImpl implements BaseService { @Resource private BaseDao baseDao; @Autowired private UserDao userDao; public void service() { baseDao.add(); } public void test() { ...

    青鸟速递管理系统详细设计文档.pdf

    青鸟速递管理系统详细设计文档.pdf 本文档详细介绍了青鸟速递管理系统的设计细节,包括员工管理、客户管理等模块的设计思路和实现细节。...BaseServiceImpl是BaseService的实现类,提供了具体的业务逻辑实现。

    mybatisPlus.zip(3.X)

    7. **Service与ServiceImpl**:MyBatisPlus提供了一套基于泛型的Service模板类,如`BaseService`和`BaseServiceImpl`,开发者可以通过继承这些类快速构建业务服务层。 8. **启动及运行指南**:压缩包可能还包含了一...

    spring+springmvc+mybatis 开发JAVA单体应用

    BaseServiceImpl 实现了通用的 CRUD 操作,提供了一个通用的服务实现。 七、 使用 Spring+SpringMVC+MyBatis 开发 JAVA 单体应用的优点 使用 Spring+SpringMVC+MyBatis 开发 JAVA 单体应用有许多优点,例如: * ...

    Spring实战之@Autowire注解用法详解

    public class BaseServiceImpl implements BaseService { // ... } ``` 在Service实现类中,可以使用@Autowire注解来自动装配DAO Bean。例如: ```java @Service public class ItemServiceImpl implements ...

    SSH框架网上商城项目第10战之搭建商品类基本模块

    - **Service层**:`ProductService`接口继承自`BaseService&lt;Product&gt;`,定义了对商品进行CRUD(创建、读取、更新、删除)操作的规范。`ProductServiceImpl`实现了这个接口,继承`BaseServiceImpl&lt;Product&gt;`,这样...

    单点登录源码

    Spring+SpringMVC+Mybatis框架集成公共模块,包括公共配置、MybatisGenerator扩展插件、通用BaseService、工具类等。 &gt; zheng-admin 基于bootstrap实现的响应式Material Design风格的通用后台管理系统,`zheng`...

Global site tag (gtag.js) - Google Analytics