/** * 根据用户ID查询出服务时数 * * @return */ public double findTime(int uid) { Sql sql = Sqls.create( "select sum(services_number) as w from t_personservices where uid=" + uid + " and queren=1"); sql.setCallback( new SqlCallback() { public Object invoke(Connection arg0, ResultSet rs, Sql sql) throws SQLException { Object o = new Object(); if (rs.next()) { o = rs.getObject("w"); } rs.close(); return o; } }); dao.execute(sql); Object o = sql.getResult(); if (o != null) { return Double.parseDouble(o.toString()); } return 0; }
/** * 根据多个id删除数据 * * @param <T> * @param c 要操作的表信息 * @param ids 要删除的id,多个用","(逗号)分隔 * @return true 成功,false 失败 */ public <T> void deleteByIds(Class<T> c, String ids) { Entity<T> entity = dao.getEntity(c); String table = entity.getTableName(); String id = entity.getIdField().getColumnName(); Sql sql = Sqls.create("delete from " + table + " where " + id + " in(" + ids + ")"); dao.execute(sql); }
/** * 通过特定的sql查询出用户按服务时间大小倒叙排序的总条数 * * @param str * @return */ public int findSqlCount(String str, String table) { Sql sql = Sqls.create("select count(*) from " + table + " where id in (" + str + ")"); sql.setCallback( new SqlCallback() { public Object invoke(Connection arg0, ResultSet rs, Sql sql) throws SQLException { while (rs.next()) { return rs.getInt(1); } return null; } }); dao.execute(sql); return sql.getInt(); }
public Sql execute(Sql sql) { if (sql != null) execute(new Sql[] {sql}); return sql; }