/** 修改数据 */ public int udpate(Position position) { String sql = "update Position "; List params = new ArrayList(); // 用户保存 要修改列的sql语句 String set = ""; if (position.getPositionName() != null && !"".equals(position.getPositionName())) { set += ",PositionName=?"; params.add(position.getPositionName()); } if (position.getCompanyId() != 0 && !"".equals(position.getCompanyId())) { set += ",CompanyId=?"; params.add(position.getCompanyId()); } if (position.getDepartmentId() != 0 && !"".equals(position.getDepartmentId())) { set += ",DepartmentId=?"; params.add(position.getDepartmentId()); } if (position.getPowerId() != 0 && !"".equals(position.getPowerId())) { set += ",PowerId=?"; params.add(position.getPowerId()); } // 重新拼接,构建完成的sql语句 sql += " set " + set.substring(1); sql += " where PositionId=?"; params.add(position.getPositionId()); int i = super.executeUpdate(sql, params); return i; }
/** 删除数据 */ public int delete(Position position) { String sql = "delete from Position where PositionId= " + position.getPositionId(); int i = super.executeUpdate(sql, null); return i; }