MyBatis数据操作的工具类,封装了获取SqlSession,提交事务或回滚事务的逻辑。
使用时需要配置文件,路径如下:classpath:jut_mybatis/mybatis.cfg.xml
mapper:
public interface CustomerMapper {
Integer deleteCustomer(Long id);
}
调用示例:
Integer result = DbUtil.execute(new CallbackInterface() {
@Override
public Integer execute(CustomerMapper mapper) {
return mapper.deleteCustomer(id);
}
},CustomerMapper.class);