public class DaoTemplate extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
primaryKeyField
本表的主键字段,请在子类中覆盖或构造方法中指定,默认为id
|
protected SqlRunner |
runner |
protected String |
tableName
表名
|
| 构造器和说明 |
|---|
DaoTemplate(String tableName) |
DaoTemplate(String tableName,
String primaryKeyField) |
DaoTemplate(String tableName,
String primaryKeyField,
SqlRunner runner) |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
add(Entity entity)
添加
|
Long |
addForGeneratedKey(Entity entity)
添加
|
List<Object> |
addForGeneratedKeys(Entity entity)
添加
|
int |
addOrUpdate(Entity entity)
增加或者更新实体
|
<T> int |
del(String field,
T value)
删除
|
<T> int |
del(T pk)
删除
|
<T> List<Entity> |
find(String field,
T value)
根据某个字段值查询结果
|
List<Entity> |
findAll()
查询当前表的所有记录
|
<T> Entity |
get(String field,
T value)
根据某个字段(最好是唯一字段)查询单个记录
|
<T> Entity |
get(T pk)
根据主键获取单个记录
|
int |
update(Entity entity)
更新职位信息
|
protected SqlRunner runner
protected String tableName
protected String primaryKeyField
public DaoTemplate(String tableName)
public int add(Entity entity) throws SQLException
entity - 实体对象SQLExceptionpublic List<Object> addForGeneratedKeys(Entity entity) throws SQLException
entity - 实体对象SQLExceptionpublic Long addForGeneratedKey(Entity entity) throws SQLException
entity - 实体对象SQLExceptionpublic <T> int del(T pk)
throws SQLException
T - 主键类型pk - 主键SQLExceptionpublic <T> int del(String field, T value) throws SQLException
T - 主键类型field - 字段名value - 字段值SQLExceptionpublic int update(Entity entity) throws SQLException
entity - 实体对象,必须包含主键SQLExceptionpublic int addOrUpdate(Entity entity) throws SQLException
entity - 实体,当包含主键时更新,否则新增SQLExceptionpublic <T> Entity get(T pk) throws SQLException
T - pk - 主键值SQLExceptionSQLExceptionpublic <T> Entity get(String field, T value) throws SQLException
T - field - 字段名value - 字段值SQLExceptionSQLExceptionpublic <T> List<Entity> find(String field, T value) throws SQLException
T - field - 字段名value - 字段值SQLExceptionSQLExceptionpublic List<Entity> findAll() throws SQLException
SQLExceptionSQLExceptionCopyright © 2015. All rights reserved.