1.SqlHelper介绍
是一个sql的辅助类,可以是代码更简洁,更有可读性!
2. 类方法方法介绍
retBool(Integer result):
判断数据库操作是否成功getObject(List<E> list):
从list中取第一条数据返回对应List中泛型的单个结果fillWrapper(Page<?> page, Wrapper<?> wrapper):
填充WrappersqlSession(Class<?> clazz):
获取SqlSession时这里虽然设置了自动提交,如果事务托管了的话 是不起作用的sqlSession(Class<?> clazz, boolean autoCommit):
获取SessionsqlSessionBatch(Class<?> clazz):
批量操作 SqlSessiontable(Class<?> clazz):
获取TableInfo
3.常用的方法使用
int update = paymentPowerAttorneyMapper.updateById(entity); if (update == 1) { throw new BusinessException(Constants.SERVICE_VERIFY_EXCEPTION_CODE, "查询失败!"); }
//使用SqlHelper后,代码简单,更美观 if (!SqlHelper.retBool(pledgeApplicationMapper.updateById(entity))) { throw new BusinessException(Constants.SERVICE_VERIFY_EXCEPTION_CODE, "查询失败!"); }
SqlHelper.retBool底层代码:
//其实对判断sql影响条数进行了封装 public static boolean retBool(Integer result) { return null != result && result >= 1; }