这是我的道路层:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
it's easier and cleaner.
这是我的application.xml
public class UserDAOImpl extends BaseDAO implements UserDAO {
private PlatformTransactionManager transactionManager;
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Override
public int storeSignUp(final StoreSignUp store) throws POSException {
KeyHolder keyHolder = new GeneratedKeyHolder();
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
int id = 0;
try {
this.jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(INSERT_STORE, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, store.getName());
ps.setString(2, store.getZip());
ps.setString(3, store.getCity());
ps.setString(4, store.getState());
ps.setInt(5, store.getCountryCode());
ps.setString(6, store.getAddress());
return ps;
}
}, keyHolder);
store.setId(keyHolder.getKey().intValue());
id = store.getId();
this.jdbcTemplate.update(INSERT_STORE_PHONE,
new Object[] { store.getId(), store.getPhone(), store.getPassword(), store.getSalt() });
transactionManager.commit(status);
} catch (DuplicateKeyException e) {
transactionManager.rollback(status);
}
return id;
}
}
我得到了
<!-- Initialization for TransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
当我调用此方法时,数据插入到一个表中但不在 另一个表,所以我想从第一个表回滚。
答案 0 :(得分:0)
这对您来说应该足够了-@Transactional(rollbackFor = {Exception.class})
其中@Transactional
是org.springframework.transaction.annotation.Transactional
假设您使用的是public
方法,请不要在该公共方法中占用Exception
,并且由于您使用的是xml配置,因此请确保您拥有
<tx:annotation-driven transaction-manager="transactionManager" />
其中tx
是-xmlns:tx="http://www.springframework.org/schema/tx"
这样,您将摆脱TransactionDefinition
,TransactionStatus
等周围的显式提交和回滚样板代码。
如果需要多种方法,这将变得很麻烦。