Spring3 JDBC 通用DAO封装1目前正在完成dao层 后续不断更新
部分代码是借鉴其他博客
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.dahua.core;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.dahua.core.page.Pager;
/**
* 基于Spring3 JDBC
* User: szj
* Date: 2012-04-01
* Time: 14:09:44
* BaseDAO 数据库连接基础类
*/
public interface BaseDao<T, ID extends Serializable> {
public Number saveAndReturnKey(Saveable objForSave);
public Number saveAndReturnKey(Object objForSave,String tableName,String...keyColumns);
public Number saveAndReturnKey(String tableName,Map<String,Object> columnAndValue,String...keyColumns);
public int addList(Collection<T> entityCollection, Class<T> entityClazz);
public int delete(T entity);
public int deleteList(Collection<T> entityCollection, Class<T> entityClazz);
public void update(T entity);
public int updateList(Collection<T> entityCollection, Class<T> entityClazz);
public void saveOrUpdate(T entity);
public List<T> getList(String sql,Class<T> entityClazz);
public List<T> getListAll(Class<T> entityClazz);
public List<T> getPageList( String hSql,Class<T> entityClazz, Pager pager);
/**
* 按某个字段查找
* @param sql
* @param columnName
* @param value
* return 返回List
*/
public List<T> findBycolumnNameList(Class<T> entityClazz, String columnName, Object value);
/**
* 按某个字段查找
* @param sql
* @param columnName
* @param value
* return 返回T
*/
public T findBycolumnName(Class<T> entityClazz, String columnName, Object value);
/**
* 按id查找
* @param sql
* @param columnName
* @param value
* return 返回T
*/
public T findByid(Class<T> entityClazz, Object value);
/**
* 统计总数
* @param sql
*/
public int countAll(String sql);
/**
* 删除数据的方法
* @param sql
* @param columns
*/
public void delete(String sql,String columns);
public int deleteById(Class<T> entityClazz, ID id);
public void update(String sql);
public void update(String sql,T entity);
}
package com.dahua.core;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.dahua.core.page.LimitPageHepler;
import com.dahua.core.page.Pager;
/**