jdbcTemplate插入后返回自增id
解决方法:
Stirng sql="INSERT INTO tb_manage_botton (botton_name) VALUES (?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
int temp = jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, “新增”);
return ps;
}
}, keyHolder);
if(temp>0){
Long id = keyHolder.getKey().longValue();
}