我有救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