//Method for automatic numbering acquisition
@PostConstruct
public void init() {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert((JdbcTemplate) template.getJdbcOperations());
SimpleJdbcInsert withTableName = simpleJdbcInsert.withTableName("orders");
insert = withTableName.usingGeneratedKeyColumns("id");
}
After inserting, get the ID assigned by automatic numbering and return
public Order insert(Order order) {
//Domain name and SQL? If there is a part, it will enter automatically
SqlParameterSource param = new BeanPropertySqlParameterSource(order);
//executeAndReturnKey executes the insert statement without permission
Number key = insert.executeAndReturnKey(param);
order.setId(key.intValue());
return order;
}
I will leave it as a memorandum. If you have any suggestions, please let me know.
Recommended Posts