我有救DB中的用户的方法和返回自动生成的ID:如何在KeyHolder中正确使用JdbcTemplate.update?
public int save(User user) {
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(SAVE_USER, user.getParams(), holder);
return holder.getKey().intValue();
}
public Object[] getParams() {
return new Object[]{
email, // String email
password}; // String password
}
SAVE_USER = INSERT INTO user (email, password) VALUES (?, ?)
当我试图执行一个方法,我发现了一个例外:
Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback;
SQL [INSERT INTO user (email, password) VALUES (?, ?)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
这是否帮助? http://stackoverflow.com/a/15436696/1325237 – Alex