本文共 1421 字,大约阅读时间需要 4 分钟。
Spring JDBC模板惯用方式 @Resource private NamedParameterJdbcTemplate jdbcTemplate; @Resource private JdbcTemplate jdbcTemplateSimple;1、插入并获取自增主键 KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplateSimple.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(insert_sql, Statement.RETURN_GENERATED_KEYS); ps.setLong(1, 2L); ps.setString(6, "test"); return ps; } }, keyHolder); long id = keyHolder.getKey().longValue();2、查询返回结果集List
转载地址:http://bbubo.baihongyu.com/