postgreSQL插入语句返回主键
来源:互联网 发布:lol域名 发展 编辑:程序博客网 时间:2024/06/05 14:28
SprimgMVCJDBC 操作postgreSql的时候,由于主键是自动增长的,所以插入时不需要制定id,但如何返回自动增长的主键呢?
public <S extends AttachmentEnt> S save(S entity) { <span style="color:#ff0000;">KeyHolder keyHolder = new GeneratedKeyHolder();</span> String sql = "INSERT INTO wl_ent_attachment (ent_id, " + "storage_type, key, mime_type, name, label, description, created_by, " + "created_time, updated_by, edit_time, status) " + "VALUES (:ent_id, :storage_type, :key, :mime_type, :name, :label, " + ":description, :created_by, :created_time, :updated_by, :edit_time, :status)"; MapSqlParameterSource term = new MapSqlParameterSource(); term.addValue("ent_id", entity.getEntId()); term.addValue("storage_type", entity.getStorageType()); term.addValue("key", entity.getKey()); term.addValue("mime_type", entity.getMimeType()); term.addValue("name", entity.getName()); term.addValue("label", entity.getLabel()); term.addValue("description", entity.getDescription()); term.addValue("created_by", entity.getCreatedBy()); term.addValue("created_time", entity.getCreatedTime()); term.addValue("updated_by", entity.getUpdatedBy()); term.addValue("edit_time", entity.getEditTime()); term.addValue("status", entity.getStatus()); <span style="color:#ff0000;">getNamedParameterJdbcTemplate().update(sql, term, keyHolder);</span> List keyList = keyHolder.getKeyList(); if (keyList != null && keyList.size() > 0) { Map map = (Map) keyList.get(0); <span style="color:#ff0000;">entity.setId(Long.parseLong(String.valueOf(map.get("id"))));</span> } return entity; }利用KeyHolder即可返回自动增长的主键!
0 0
- postgreSQL插入语句返回主键
- Mybatis-插入语句返回ID主键
- spring 插入语句的时候 返回主键
- mybatis insert 插入语句返回主键
- sql插入语句返回自增主键
- MyBatis插入语句返回主键值
- JDBC Insert语句插入Oracle数据库返回数据主键
- 关于MyBatis插入语句,返回主键的值
- JDBC之获取插入语句返回的主键
- 数据库插入返回主键
- ibatis插入返回主键
- jdbc插入返回主键
- mybitas插入返回主键
- mybitas插入返回主键
- mybatis 插入返回主键
- postgresql插入后返回id
- myibatis插入后返回主键
- mybatis3.x 插入返回主键
- 旋转数组最小值(算法)
- 希尔排序-ShellSort
- C++智能指针
- C++ 单例模式
- Sizzle选择器引擎介绍
- postgreSQL插入语句返回主键
- OCX 打包 CAB 与 JS 调用详细教程
- Excel统计某字符或关键字出现的次数
- setLatestEventInfo(),Builder.getNotification()过时,Android提供的解决方案
- 异常安全的C++类
- 有关HashMap和Hashtable的区别简易分析
- matlab基础
- Workbook解析excel文件 读取信息
- JAVA问题总结之8-byte和short数据相互加减