使用Spring JDBC,当我尝试将记录插入表中时,它正在被插入,但是当我添加KeyHolder以了解生成的键时,它将抛出NullPOinterException
@Repository
public class TestDAO {
@Transactional(propagation = Propagation.MANDATORY)
public Long create(TestEntity entity) {
KeyHolder holder = new GeneratedKeyHolder();
SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(entity);
jdbc.update(insertQuery, namedParameters, holder);
return entity.getID();
}
}
我是spring-jdbc的新手。有人可以帮忙吗?