@Component public class JdbcTemplateUtils extends Object
| 构造器和说明 |
|---|
JdbcTemplateUtils(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate) |
JdbcTemplateUtils(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
@NotNull String tableName) |
| 限定符和类型 | 方法和说明 |
|---|---|
List<Long> |
batchAddWithId(@NotNull String tableName,
String[] fields,
List<Map<String,Object>> list)
批量插入数据,由于JDBCTemplate不支持批量插入后返回批量id,所以此处使用jdbc原生的方法实现此功能
|
int[] |
batchInsert(@NotNull String tableName,
List<Map<String,Object>> listData)
批量插入数据
|
void |
batchInsert(@NotNull String tableName,
String[] fields,
List<Map<String,Object>> list)
批量插入数据,不考虑是否重复等因素
|
void |
batchInsert(@NotNull String tableName,
String[] fields,
List<Map<String,Object>> list,
boolean ignore)
批量新增,默认不使用insert ignore的形式插入数据
|
long |
count(String tableName,
Map<String,String> where)
根据Where条件求Count
|
long |
count(@NotNull String tableName,
@NotNull String alias,
Map<String,String> where)
总数
|
Integer |
delete(@NotNull String tableName,
@NotNull String idFiledName,
@NotNull String id)
删除数据
|
Map<String,Object> |
findById(@NotNull String tableName,
@NotNull String idFiledName,
@NotNull String id)
根据id字段进行查询
|
<T> T |
findById(@NotNull String tableName,
@NotNull String idFiledName,
@NotNull String id,
Class<T> elementType)
根据ID查询 返回实体对象
|
Map<String,Object> |
findOne(@NotNull String sql)
自定义查询
|
Map<String,Object> |
findOne(@NotNull String sql,
Object[] params)
自定义传参查询
|
Integer |
insert(@NotNull String tableName,
Map<String,Object> map)
新增数据
|
List<Map<String,Object>> |
queryForList(@NotNull String sql)
原生的 queryForList查询
|
<T> List<T> |
queryForList(@NotNull String sql,
Class<T> elementType)
原生的 queryForList 不能直接转到实体,会产生异常,原生只支持基本类型转换,不支持实体类型转换
|
List<Map<String,Object>> |
queryForList(@NotNull String sql,
Object[] params)
原生的 queryForList查询 自定义传参
|
<T> List<T> |
queryForList(@NotNull String sql,
Object[] params,
org.springframework.jdbc.core.BeanPropertyRowMapper<T> beanPropertyRowMapper)
直接用sql查询转实体
|
<T> List<T> |
queryForList(@NotNull String sql,
Object[] params,
Class<T> elementType)
原生的 queryForList 不能直接转到实体,会产生异常,原生只支持基本类型转换,不支持实体类型转换 自定义传参
|
int |
update(String sql,
List<Object> params)
更新
|
int |
update(@NotNull String tableName,
Map<String,Object> map,
LinkedHashMap<String,Object> whereMap)
修改数据
|
public JdbcTemplateUtils(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
jdbcTemplate - public JdbcTemplateUtils(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
@NotNull
@NotNull String tableName)
jdbcTemplate - tableName - public Integer insert(@NotNull @NotNull String tableName, Map<String,Object> map)
map - 字段和Value值,放入Map中入库public int[] batchInsert(@NotNull
@NotNull String tableName,
List<Map<String,Object>> listData)
listData - public void batchInsert(@NotNull
@NotNull String tableName,
String[] fields,
List<Map<String,Object>> list)
throws Exception
tableName - 表名fields - 字段列表list - 数据列表Exceptionpublic void batchInsert(@NotNull
@NotNull String tableName,
String[] fields,
List<Map<String,Object>> list,
boolean ignore)
tableName - fields - list - ignore - 是否重复,如果重复的话,会使用insert ignore忽略插入的形式进行数据插入Exceptionpublic List<Long> batchAddWithId(@NotNull @NotNull String tableName, String[] fields, List<Map<String,Object>> list) throws Exception
tableName - fields - list - Exceptionpublic int update(String sql, List<Object> params)
sql - 自定义更新sqlparams - 查询条件对应的参数(Listpublic int update(@NotNull
@NotNull String tableName,
Map<String,Object> map,
LinkedHashMap<String,Object> whereMap)
map - 修改的字段集合whereMap - where 参数集合public Map<String,Object> findOne(@NotNull @NotNull String sql, Object[] params)
sql - params - public Map<String,Object> findById(@NotNull @NotNull String tableName, @NotNull @NotNull String idFiledName, @NotNull @NotNull String id)
tableName - idFiledName - id - public <T> T findById(@NotNull
@NotNull String tableName,
@NotNull
@NotNull String idFiledName,
@NotNull
@NotNull String id,
Class<T> elementType)
T - tableName - idFiledName - id - elementType - public List<Map<String,Object>> queryForList(@NotNull @NotNull String sql)
sql - public List<Map<String,Object>> queryForList(@NotNull @NotNull String sql, Object[] params)
sql - params - public <T> List<T> queryForList(@NotNull @NotNull String sql, Class<T> elementType)
T - sql - elementType - public <T> List<T> queryForList(@NotNull @NotNull String sql, Object[] params, Class<T> elementType)
T - sql - params - elementType - public <T> List<T> queryForList(@NotNull @NotNull String sql, Object[] params, org.springframework.jdbc.core.BeanPropertyRowMapper<T> beanPropertyRowMapper)
T - sql - params - beanPropertyRowMapper - public Integer delete(@NotNull @NotNull String tableName, @NotNull @NotNull String idFiledName, @NotNull @NotNull String id)
id - public long count(@NotNull
@NotNull String tableName,
@NotNull
@NotNull String alias,
Map<String,String> where)
tableName - 表名alias - 主表别名where - 查询条件ExceptionCopyright © 2024. All rights reserved.