public int insertCustomer(final Customer customer) {
//TODO.
final String sql = "insert into customer (mobile,nickname,password,score,avatar,push_key,reg_time) values(?,?,?,?,?,?,now())";
KeyHolder keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, customer.getMobile());
ps.setString(2, customer.getNickname());
ps.setString(3, customer.getPassword());
ps.setInt(4, customer.getScore());
ps.setString(5, customer.getAvatar());
ps.setString(6,customer.getPushKey());
// ps.setString(7, customer.getRegTime());
return ps;
}
}, keyHolder);
return keyHolder.getKey().intValue();
}
相关文章
- 01-19插入数据:返回记录的id值
- 01-19Mybatis使用Map当做参数获取插入数据成功后返回的自增id
- 01-19Mybatis插入数据返回主键
- 01-19(办公)springmvc->controller的统一异常层,返回json
- 01-19主键无序插入对性能的影响以及innodb buffer的效率指标分析
- 01-19MyBatis插入返回主键id
- 01-19insert一句话实现插入一条数据并且返回这条数据的某列
- 01-19使用SQLServer2005插入一条数据时返回当前插入数据的ID
- 01-19SpringMVC controller中业务方法的参数、返回值
- 01-19实现插入数据后返回自增主键ID的几种方式