GreenDao 3.3.0 增删改查的使用(三)
GreenDao 3.3.0 多表关联使用(二)
GreenDao 的数据操作处理是继承自AbstractDao这个抽象类
最基本的函数:
- insert(T) delete(T) update(T) save(T) insertOrReplace(T) loadAll()
- 其中 save(T) 和insertOrReplace(T) 方法比较特殊既能进行插入操作也能执行修改操作
- insertInTx(T…) deleteInTx(T…) updateInTx(T…) saveInTx(T…) insertOrReplaceInTx(T…)
- refresh(T) 刷新数据
注意:在这函数后面有InTx(T…),是表示开启事物进行多个数据的操作
/*** Inserts the given entities in the database using a transaction.** @param entities The entities to insert.*/public void insertInTx(T... entities) {insertInTx(Arrays.asList(entities), isEntityUpdateable());}/*** Inserts the given entities in the database using a transaction. The given entities will become tracked if the PK* is set.** @param entities The entities to insert.* @param setPrimaryKey if true, the PKs of the given will be set after the insert; pass false to improve* performance.*/public void insertInTx(Iterable<T> entities, boolean setPrimaryKey) {DatabaseStatement stmt = statements.getInsertStatement();executeInsertInTx(stmt, entities, setPrimaryKey);}private void executeInsertInTx(DatabaseStatement stmt, Iterable<T> entities, boolean setPrimaryKey) {db.beginTransaction();try {synchronized (stmt) {if (identityScope != null) {identityScope.lock();}try {if (isStandardSQLite) {SQLiteStatement rawStmt = (SQLiteStatement) stmt.getRawStatement();for (T entity : entities) {bindValues(rawStmt, entity);if (setPrimaryKey) {long rowId = rawStmt.executeInsert();updateKeyAfterInsertAndAttach(entity, rowId, false);} else {rawStmt.execute();}}} else {for (T entity : entities) {bindValues(stmt, entity);if (setPrimaryKey) {long rowId = stmt.executeInsert();updateKeyAfterInsertAndAttach(entity, rowId, false);} else {stmt.execute();}}}} finally {if (identityScope != null) {identityScope.unlock();}}}db.setTransactionSuccessful();} finally {db.endTransaction();}}
save 和 insertOrReplace 区别
save it will be inserted (key is null) or updated (key is not null)
有key的对象执行更新,无key的执行插入
当对象有key但并不在数据库时会执行失败.适用于保存本地列表
/*** "Saves" an entity to the database: depending on the existence of the key property, it will be inserted* (key is null) or updated (key is not null).* <p>* This is similar to {@link #insertOrReplace(Object)}, but may be more efficient, because if a key is present,* it does not have to query if that key already exists.*/public void save(T entity) {if (hasKey(entity)) {update(entity);} else {insert(entity);}}
insertOrReplace
传入的对象在数据库中,有则更新无则插入,源码显示带有事物和线程
推荐同步数据库时使用该方法
/*** Insert an entity into the table associated with a concrete DAO.** @return row ID of newly inserted entity*/public long insertOrReplace(T entity) {return executeInsert(entity, statements.getInsertOrReplaceStatement(), true);}private long executeInsert(T entity, DatabaseStatement stmt, boolean setKeyAndAttach) {long rowId;if (db.isDbLockedByCurrentThread()) {rowId = insertInsideTx(entity, stmt);} else {// Do TX to acquire a connection before locking the stmt to avoid deadlocksdb.beginTransaction();try {rowId = insertInsideTx(entity, stmt);db.setTransactionSuccessful();} finally {db.endTransaction();}}if (setKeyAndAttach) {updateKeyAfterInsertAndAttach(entity, rowId, true);}return rowId;}
QueryBuilder 构建查询语
支持函数查询条件 distinct、 where 、whereOr 、or 、and、 OrderAsc/Desc、 join、 limit/offset(分页两个合用) 等具体查看QueryBuilder API
构建对象 CursorQuery buildCursor()、List list()、 T unique()、 T uniqueOrThrow()、 DeleteQuery buildDelete() 等
Property 配置where 条件判断
- eq():==
- noteq():!= ,"<>?"
- gt(): >
- lt():<
- ge:>=
- le:<=
- like():包含
- between:俩者之间
- in:在某个值内
- notIn:不在某个值内
- isNull: is null
- isNotNull: is not null
分页查询
- limit(int): 限制查询的数量;
- offset(int): 每次返回的数量; offset不能单独使用;
查询与LazyList类
Query : Query类表示一个查询能够执行很多次;而当通过QueryBuilder的任何查询方法(eg:list())来获取查询结果时,querybuilder都会 在其内部创建Query来执行查询语句的;如果执行多次查询应该使用Query对象; 如果只想获取一个结果时可以使用Query(or QueryBuilder)中的unique()方法;LazyList : 可以通过以下方法获取查询结果集合;list() 缓存查询结果;list()类型一般为ArrayListlistLazy() 懒查询,只有当调用list()中的实体对象时才会执行查询操作并且只缓存第一次被查询的结果,需要关闭listlazyUncached() 懒查询,只有当调用list()中的实体对象时才会执行查询操作并且不缓存;listIterator() 对查询结果进行遍历,不缓存,需要关闭;后面三个类是LazyList中的方法,LazyList为了执行不同的缓存策略其内部持有数据库的cursor对象;一般情况下这三个方法执行完毕后会自动关闭cursor;但是防止在还没有执行完查询结果时,对象被终结cursor还是无法被关闭的情况发生,需要手动关闭close();
getDaoSession/getDatabase 开启事物处理
getDatabase 开启
Database database = getDaoSession().getMessageEntityDao().getDatabase();Cursor cursor = null;ArrayList<MessageEntity> dataList = new ArrayList<MessageEntity>();try {database.beginTransaction();cursor = database.rawQuery(sql, null);while (cursor.moveToNext()) {MessageEntity data = createMessageEntity(cursor);dataList.add(data);}database.setTransactionSuccessful();} catch (Exception e) {LogUtil.e(TAG, "QueryMessageEntity " + e);} finally {if (database != null)database.endTransaction();if (null != cursor) {cursor.close();}}
getDaoSession 开启
/*** Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't* except a result, consider runInTx.*/public <V> V callInTx(Callable<V> callable) throws Exception {db.beginTransaction();try {V result = callable.call();db.setTransactionSuccessful();return result;} finally {db.endTransaction();}}
callInTx 事物处理 执行查询操作
/*** @param type -1:设备账户 ,0:app主账户,1:app一般账户* @return*/public synchronized ArrayList<AccountInformation> getUserData(final int type) {ArrayList<AccountInformation> userList = null;try {userList = (ArrayList<AccountInformation>) getDaoSession().callInTx(new Callable<List<AccountInformation>>() {@Overridepublic List<AccountInformation> call() {return getDaoSession().getAccountInformationDao().queryBuilder().where(AccountInformationDao.Properties.UserType.eq(type)).build().list();}});} catch (Exception e) {LogUtil.e(TAG, "getUserData " + e);}return userList;}
getDaoSession runInTx 开启线程处理
* Run the given Runnable inside a database transaction. If you except a result, consider callInTx.*/public void runInTx(Runnable runnable) {db.beginTransaction();try {runnable.run();db.setTransactionSuccessful();} finally {db.endTransaction();}}
insertOrReplace 新增或修改数据
/*** 增加或修改用户信息** @param* @return*/public synchronized boolean setUserData(AccountInformation entity) {try {AccountInformationDao dao = getDaoSession().getAccountInformationDao();AccountInformation user = dao.queryBuilder().where(AccountInformationDao.Properties.UserId.eq(entity.getUserId())).build().unique();if (user != null) {entity.setId(user.getId());}dao.insertOrReplace(entity);dao.refresh(entity);return true;} catch (Exception e) {LogUtil.e(TAG, "setUserData " + e);return false;}}
QueryBuilder 切换条件执行查询语句
public synchronized ArrayList<UrlInformation> QueryUrlInfomationList(final int type, final int commandType, final String url, final long recordId, final int isUpload, final long createTime) {ArrayList<UrlInformation> dataList = null;try {dataList = (ArrayList<UrlInformation>) getDaoSession().callInTx(new Callable<List<UrlInformation>>() {@Overridepublic List<UrlInformation> call() throws Exception {UrlInformationDao dao = getDaoSession().getUrlInformationDao();QueryBuilder<UrlInformation> queryBuilder = dao.queryBuilder();if (type == 1) {queryBuilder.where(UrlInformationDao.Properties.CommentType.eq(commandType));} else if (type == 5) {queryBuilder.where(UrlInformationDao.Properties.CommentType.eq(commandType),UrlInformationDao.Properties.CreateTime.eq(createTime));} else if (type == 6) {/* sql = "select * from " + Provider.UrlInformation.TABLE_NAME+ " where "+ Provider.UrlInformation.commentType + " = '"+ commandType + "'"+ " and "+ Provider.UrlInformation.url +"<>'' and '"+url +"' LIKE '%'||"+Provider.UrlInformation.url + "||'%'";*/queryBuilder.where(UrlInformationDao.Properties.CommentType.eq(commandType),UrlInformationDao.Properties.Url.like("%" + url + "%"));}return queryBuilder.build().list();}});} catch (Exception e) {LogUtil.e(TAG, "QueryUrlInfomationList " + e);}return dataList;
执行SQL语句
rawQuery queryRawCreate execSQL
public long queryUserMaxId() {long id=0;try {UsersDao userDao = getDaoSession().getUsersDao();String sql = "select max("+UsersDao.Properties.Id.columnName+") "+UsersDao.Properties.Id.columnName+" from " + UsersDao.TABLENAME;sql = "select max(_id) as maxId"+" from " + UsersDao.TABLENAME;// sql="select * from "+UserDao.TABLENAME;Cursor cursor = userDao.getDatabase().rawQuery(sql, null);if (cursor.moveToNext()){//moveToNext moveToLast//id = cursor.getLong(cursor.getColumnIndex(UserDao.Properties.Id.columnName));id = cursor.getLong(cursor.getColumnIndex("maxId"));Log.d(TAG,"queryUserMaxId cursor users id="+id);}cursor.close();return id;} catch (Exception e) {e.printStackTrace();Log.d(TAG,"queryUserMaxId cursor Exception"+e);}return 0;
}
QueryBuilder buildDelete 带事物删除
适用于数据量比较大批量删除
/*** Builds a reusable query object for deletion (Query objects can be executed more efficiently than creating a* QueryBuilder for each execution.*/public DeleteQuery<T> buildDelete() {if (!joins.isEmpty()) {throw new DaoException("JOINs are not supported for DELETE queries");}String tablename = dao.getTablename();String baseSql = SqlUtils.createSqlDelete(tablename, null);StringBuilder builder = new StringBuilder(baseSql);// tablePrefix gets replaced by table name below. Don't use tableName here because it causes trouble when// table name ends with tablePrefix.appendJoinsAndWheres(builder, tablePrefix);String sql = builder.toString();// Remove table aliases, not supported for DELETE queries.// TODO(?): don't create table aliases in the first place.sql = sql.replace(tablePrefix + ".\"", '"' + tablename + "\".\"");checkLog(sql);return DeleteQuery.create(dao, sql, values.toArray());}
/*** 删除所有家长端用户** @param* @return*/public synchronized boolean deleteUserByType() {try {getDaoSession().getAccountInformationDao().queryBuilder().where(AccountInformationDao.Properties.UserType.gt(-1)).buildDelete().executeDeleteWithoutDetachingEntities();return true;} catch (Exception e) {LogUtil.e(TAG, "deleteUserByType " + e);return false;}}
Query SQL 查询
QueryBuilder>build()
Query对象一旦生成就能多次被使用,你也可以为下一次查询增加查询条件
Query query = userDao.queryBuilder().where( new
StringCondition("_ID IN " + "(SELECT USER_ID FROM
USER WHERE READ_ID = 0)")).build();//分组查询
Query query = userDao.queryRawCreate( ", GROUP G WHERE
G.NAME=? AND T.GROUP_ID=G._ID", "admin");Query query = userDao.queryBuilder().where(
userDao.Properties.IsRead.gt(0),
userDao.Properties.DistinctName.eq("yes")).build();List userFirst = query.list(); query.setParameter(0, 1);
query.setParameter(1, "no");List userSecond = query.list();
自定义SQL 拼接多个查询语句
/*** 聊天消息查询** @param type 1: 根据messaId查询,2:查询所有消息,3:群消息根据时间查询(大于),4:群消息根据时间查询(小于),5:私聊消息根据时间查询(大于),* 6:私聊消息根据时间查询(小于),7:当前消息根据时间查询(大于),6:当前消息根据时间查询(小于)* @param messageId 消息Id 传私人Id为私聊消息,传群Id,为群聊消息* @param time 时间* @param order 只能传 DESC(由大到小)和ASC(由小到大)* @param size 查询数据的数量* @return* @userId userId:自己用户id* @groupId 私聊方Id或群id*/public synchronized ArrayList<MessageEntity> QueryMessageList(int type, long messageId, long userId, long reuserid, String time, int size, String order) {String sql = null;Database database = getDaoSession().getMessageEntityDao().getDatabase();if (type == 1) {sql = "select * from " + MessageEntityDao.TABLENAME+ " where " + MessageEntityDao.Properties.MessageId.columnName + " = '" + messageId + "'";} else if (type == 2) {sql = "select * from " + MessageEntityDao.TABLENAME;} else if (type == 3) {sql = "select * from " + MessageEntityDao.TABLENAME+ " where " + MessageEntityDao.Properties.ReuserId.columnName + " = '" + reuserid + "'"+ " and " + MessageEntityDao.Properties.CreateTime.columnName + " > '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";} else if (type == 4) {sql = "select * from " + MessageEntityDao.TABLENAME+ " where " + MessageEntityDao.Properties.ReuserId.columnName + " = '" + reuserid + "'"+ " and " + MessageEntityDao.Properties.CreateTime.columnName + " < '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";} else if (type == 5) {sql = "select * from '" + MessageEntityDao.TABLENAME + "'" + " where "+ " ( " + " ( " + MessageEntityDao.Properties.UserId.columnName + " = '" + reuserid + "' and "+ MessageEntityDao.Properties.ReuserId.columnName + " = '" + userId + "' ) " + " or "+ " ( " + MessageEntityDao.Properties.UserId.columnName + " = '" + userId + "' and "+ MessageEntityDao.Properties.ReuserId.columnName + " = '" + reuserid + "' ) " + " ) "+ " and " + MessageEntityDao.Properties.CreateTime.columnName + " > '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";} else if (type == 6) {sql = "select * from '" + MessageEntityDao.TABLENAME + "'" + " where "+ " ( " + " ( " + MessageEntityDao.Properties.UserId.columnName + " = '" + reuserid + "' and "+ MessageEntityDao.Properties.ReuserId.columnName + " = '" + userId + "' ) " + " or "+ " ( " + MessageEntityDao.Properties.UserId.columnName + " = '" + userId + "' and "+ MessageEntityDao.Properties.ReuserId.columnName + " = '" + reuserid + "' ) " + " ) "+ " and " + MessageEntityDao.Properties.CreateTime.columnName + " < '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";} else if (type == 7) {sql = "select * from '" + MessageEntityDao.TABLENAME + "'" + " where "+ MessageEntityDao.Properties.CreateTime.columnName + " > '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";} else if (type == 8) {sql = "select * from messagelist t where EXISTS ( select 1 from messagelist GROUP BY distinctName HAVING MAX(_id) = t._id)"+ " and " + MessageEntityDao.Properties.CreateTime.columnName + " < '" + time + "'"+ " order by " + MessageEntityDao.Properties.CreateTime.columnName + " " + order + " limit '" + size + "' offset '" + 0 + "'";//+Provider.MessageEntity.commenType + " = '" + comment + "'"//SELECT * FROM test_table t WHERE EXISTS ( SELECT 1 FROM test_table GROUP BY uname HAVING MAX(id) = t.id )}LogUtil.d(TAG, "QueryMessageEntity ,sql:" + sql);Cursor cursor = null;ArrayList<MessageEntity> dataList = new ArrayList<MessageEntity>();try {database.beginTransaction();cursor = database.rawQuery(sql, null);while (cursor.moveToNext()) {MessageEntity data = createMessageEntity(cursor);dataList.add(data);}database.setTransactionSuccessful();} catch (Exception e) {LogUtil.e(TAG, "QueryMessageEntity " + e);} finally {if (database != null)database.endTransaction();if (null != cursor) {cursor.close();}}return dataList;}
/*** 创建消息实体** @param cursor* @return*/public MessageEntity createMessageEntity(Cursor cursor) {MessageEntity data = new MessageEntity();data.setChatType(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.ChatType.columnName)));data.setMessageId(cursor.getLong(cursor.getColumnIndex(MessageEntityDao.Properties.MessageId.columnName)));data.setMessageType(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.MessageType.columnName)));data.setUserId(cursor.getLong(cursor.getColumnIndex(MessageEntityDao.Properties.UserId.columnName)));data.setUserName(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.UserName.columnName)));data.setUserPic(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.UserPic.columnName)));data.setReuserId(cursor.getLong(cursor.getColumnIndex(MessageEntityDao.Properties.ReuserId.columnName)));data.setReuserName(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.ReuserName.columnName)));data.setReuserPic(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.ReuserPic.columnName)));data.setMcontent(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.Mcontent.columnName)));data.setCreateTime(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.CreateTime.columnName)));data.setIsRead(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.IsRead.columnName)));data.setIsSend(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.IsSend.columnName)));data.setMessageSize(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.MessageSize.columnName)));data.setSubCode(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.SubCode.columnName)));data.setSendType(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.SendType.columnName)));data.setReceType(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.ReceType.columnName)));data.setSubGroup(cursor.getInt(cursor.getColumnIndex(MessageEntityDao.Properties.SubGroup.columnName)));data.setLocalityContent(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.LocalityContent.columnName)));data.setDistinctName(cursor.getString(cursor.getColumnIndex(MessageEntityDao.Properties.DistinctName.columnName)));return data;}
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
相关文章
- Python list中dist统计
#关于Python中list里的dist按照某一个key相同的value统计另一个key的value个人简述。代码不是很优美,欢迎大佬指点 lst = [{"name": "Apple", "qty": 10}, {"name": "Apple", "qty": 5}, {"name": &qu…...
2024/5/5 3:14:16 - pytorch学习记录
torch.nn.MSEloss 计算公式:loss_fn = torch.nn.MSELoss()例子 import torch loss_fn = torch.nn.MSELoss() input = torch.randn(1,2) target = torch.autograd.Variable(torch.randn(1,2)) loss = loss_fn(input, target) print(input); print(target); print(loss) print(i…...
2024/5/4 17:18:27 - 将一个头结点为A的单链表分解成两个单链表A和B
求:将一个头结点为A的单链表分解成两个单链表A和B,A链表只含原链表中值域为奇数的结点, B链表只含有值域为偶数的结点,且保持原来的相对顺序 算法思想:用p从头至尾扫描,扫描到偶数结点则在A中删摘下,尾插到B中 (摘下结点不需释放) void split(LNode *A,LNode *&B…...
2024/5/4 4:43:17 - 使用Crucible和FishEye链接svn库时遇到尝试添加或索引存储库时出现错误-版本中不存在的问题
问题尝试添加或索引存储库时发生错误。以下内容出现在 atlassian-fisheye-YYYY-MM-DD.log:例子1例子2原因:可能的原因包括:原因1-这可能是由错误定义的SVN URL引起的-特别是如果未将SVN URL设置为等于存储库根目录。例如:SVN URL = http://example.atlassian.com/svn/proj…...
2024/4/9 1:27:18 - 这里所说的系统模块划分,是针对client,service,common
前言首先明确一下,这里所说的系统模块划分,是针对client,service,common这样的技术划分,而不是针对具体业务的模块划分。避免由于歧义,造成你的时间浪费。直接原因公司内部某技术团队,在引用我们系统的client包时,启动失败。 失败原因是由于client下有一个cache相关的依…...
2024/4/9 1:27:17 - 17、linux日志管理-日志轮替
待续...
2024/4/9 1:27:17 - 多种方法解LeetCode4.寻找两个有序数组的中位数
目录题目:sort大法:还能更好吗?类双下标排序题目:sort大法:可以很快解决,但是因为数组之前就已经排好序,使用sort会有很多浪费:class Solution { public:double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {//本身就是有序的…...
2024/4/25 22:54:31 - 爬某国外api的图片无法解析问题与方法
图片为base64编码后的字符串 我一直用data:image/png;base64,试 都没有办法显示一直想办法 找答案 最终被我发现 接口其他数据也是ascii编码 会不会图片也是编码过于是找了某网站ascii解码了一下放入地址解码后的地址,完美解决 找了将近一个小时原因 因为字符串是图片的字节来的…...
2024/4/25 9:57:58 - 一个读取*.csv文件的工具的源代码
一个读取*.csv文件的工具的源代码,利用对话框加入列表,将*.csv文件读入列表并显示到屏幕。有列序功能、对齐功能,是Everything输出和一些*.csv输出设备的快速浏览。注意使用前应将文本转换至ANSI格式。`#include “stdafx.h” #include “★文件制表.h” WORD kkk[100];//列…...
2024/4/8 22:07:17 - SSM框架下,druid给数据库加密
下载完druid-1.1.20.jar执行命令行:java -cp druid-1.1.20.jar com.alibaba.druid.filter.config.ConfigTools 123得到如下:得到私钥,公钥,和密码加密字符串注:123是数据库密码。XML配置文件中数据库配置<!--加载配置文件--><bean id="configproperties&quo…...
2024/4/8 22:07:16 - php for一层循环 解决两个有序数组组成一个有序数组
php for一层循环 解决两个有序数组组成一个有序数组 public function reNum() {$arr1 = [1,5,7];$arr2 = [3,4];$data = [];$a = 0;for($i=0;$i<count($arr1)||$a<=count($arr2);){$num1 = $arr1[$i];$num2 = $arr2[$a];if($num1>=$num2){$data[]= $arr1[$i];$i++;}el…...
2024/4/21 12:32:41 - c++ 抽象类接口
接口描述了类的行为和功能,并且不需要去完成功能的具体实现C++ 接口是使用抽象类来实现的如果类中至少有一个函数被声明为纯虚函数,则这个类就是抽象类,而可以在类里实例化对象的称为具体类什么是虚函数呢?虚函数 是在基类中使用关键字 virtual 声明的函数。在派生类中重新…...
2024/4/11 6:47:38 - 订单组件父组件结构封装
订单组件父组件结构封装 首先我们可以发现orderconfirm orderpay orderlist 这三个组件的 orderheader组件都是复用的,只是内容不一样,我们可以封装在order组件中,不用再一个一个组件的引用,直接渲染即可:...
2024/4/25 21:14:40 - 洛谷P1443 Java解法
题目出处思路:既然题目标签是广搜,那么我们就用BFS做即可(事实证明此题广搜比深搜快不少) BFS:全称广度优先搜索,顾名思义,一层一层的遍历 DFS:全程深度优先搜索,顾名思义,一条路走到黑,完事再回来走别的路 对于此题(选择一层一层遍历也就是BFS): 1、找到所有可以通过…...
2024/5/2 3:22:47 - Ubuntu 16.04镜像文件下载
官方下载地址(不推荐) https://www.ubuntu.com/download 中科大源 http://mirrors.ustc.edu.cn/ubuntu-releases/16.04/ 阿里云开源镜像站 http://mirrors.aliyun.com/ubuntu-releases/16.04/ 兰州大学开源镜像站 http://mirror.lzu.edu.cn/ubuntu-releases/16.04/ 北京理工…...
2024/4/9 1:27:11 - 软件测试流程及BUG的定位(个人学习笔记,勿喷)
软件测试流程 需求分析阶段 1.需求:产品原型,思维导图/需求文档,口述(超级坑) 2.对需求进行熟悉学习,弄明白每个功能是怎么样子的,软件业务操作流程是什么样子的,不懂就问 3.画业务流程图 4.提取功能点 5.需求分析说明书 6.特殊情况:没有需求文档,没有产品经理时: ①…...
2024/4/14 8:20:22 - substring切割字符串
String str1 = "HelloWorld";System.out.println(str1.substring(5)); //WorldSystem.out.println(str1.substring(4,7)); //oWo. . public String substring(int index)截取参数位置一直到字符串末尾,返回新字符串 . . public String substring(int begin,…...
2024/4/9 1:27:09 - 字符串反转 - 面试题
1、题目描述 - 如题2、上代码package 剑指Offfer;import java.io.InputStreamReader; import java.util.Scanner;public class 字符串反转 {public static void main(String[] args) {Scanner in = new Scanner(new InputStreamReader(System.in));String str = in.next();char…...
2024/4/24 15:29:23 - Datawhale组队学习——打卡任务Task1赛题理解
Datawhale组队学习——打卡任务Task1赛题理解 赛题理解 赛题名称:零基础入门NLP之新闻文本分类 赛题目标:入门自然语言处理,接触NLP的预处理、模型构建和模型训练 赛题任务:对新闻文本进行分类属于典型的字符识别问题 学习目标 理解赛题背景与赛题数据 完成赛题报名和数据下…...
2024/4/9 1:27:07 - ubuntu18下 vnc server 安装
目录1. 安装桌面环境和 vnc 服务器1.1 对系统和包进行更新1.2 在服务器上安装Xfce桌面环境1.3 服务器安装完成后安装TightVNC2. 配置VNC服务器2.1 更改VNC服务器的配置方式2.2 备份原始文件3. 将vnc作为系统服务运行进root权限操作1. 安装桌面环境和 vnc 服务器1.1 对系统和包进…...
2024/4/9 1:27:06
最新文章
- list 的模拟实现
目录 1. list 的实现框架 2. push_back 3. 迭代器 4. constructor 4.1. default 4.2. fill 4.3. range 4.4. initializer list 5. insert 6. erase 7. clear 和 destructor 8. copy constructor 9. operator 10. const_iterator 10.1. 普通人的处理方案 10.2. …...
2024/5/6 8:38:29 - 梯度消失和梯度爆炸的一些处理方法
在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言,在此感激不尽。 权重和梯度的更新公式如下: w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...
2024/3/20 10:50:27 - 云计算概述报告
以下是一篇论述类文章 文章目录 I. 云计算介绍(1)云计算基本概念(2)云计算基本特征 II. 云计算发展历程(1)云计算的起源(2)云计算的发展阶段 III. 云计算特点(1ÿ…...
2024/5/5 23:20:32 - 金融数据_PySpark-3.0.3决策树(DecisionTreeClassifier)实例
金融数据_PySpark-3.0.3决策树(DecisionTreeClassifier)实例 逻辑回归: 逻辑回归常被用于二分类问题, 比如涨跌预测。你可以将涨跌标记为类别, 然后使用逻辑回归进行训练。 决策树和随机森林: 决策树和随机森林是用于分类问题的强大模型。它们能够处理非线性关系, 并且对于特…...
2024/5/4 17:20:04 - 416. 分割等和子集问题(动态规划)
题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义:dp[i][j]表示当背包容量为j,用前i个物品是否正好可以将背包填满ÿ…...
2024/5/5 18:19:03 - 【Java】ExcelWriter自适应宽度工具类(支持中文)
工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...
2024/5/5 12:22:20 - Spring cloud负载均衡@LoadBalanced LoadBalancerClient
LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon,直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件,我们讨论Spring负载均衡以Spring Cloud2020之后版本为主,学习Spring Cloud LoadBalance,暂不讨论Ribbon…...
2024/5/5 19:59:54 - TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案
一、背景需求分析 在工业产业园、化工园或生产制造园区中,周界防范意义重大,对园区的安全起到重要的作用。常规的安防方式是采用人员巡查,人力投入成本大而且效率低。周界一旦被破坏或入侵,会影响园区人员和资产安全,…...
2024/5/6 7:24:07 - VB.net WebBrowser网页元素抓取分析方法
在用WebBrowser编程实现网页操作自动化时,常要分析网页Html,例如网页在加载数据时,常会显示“系统处理中,请稍候..”,我们需要在数据加载完成后才能继续下一步操作,如何抓取这个信息的网页html元素变化&…...
2024/5/5 15:25:47 - 【Objective-C】Objective-C汇总
方法定义 参考:https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...
2024/5/6 6:01:13 - 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】
👨💻博客主页:花无缺 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】🌏题目描述🌏输入格…...
2024/5/6 7:24:06 - 【ES6.0】- 扩展运算符(...)
【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数࿰…...
2024/5/6 1:08:53 - 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?
文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕,各大品牌纷纷晒出优异的成绩单,摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称,在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁,多个平台数据都表现出极度异常…...
2024/5/5 18:50:00 - Go语言常用命令详解(二)
文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令,这些命令可以帮助您在Go开发中进行编译、测试、运行和…...
2024/5/6 0:27:44 - 用欧拉路径判断图同构推出reverse合法性:1116T4
http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b,我们在 a i a_i ai 和 a i 1 a_{i1} ai1 之间连边, b b b 同理,则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然࿰…...
2024/5/6 7:24:04 - 【NGINX--1】基础知识
1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息,并安装一些有助于配置官方 NGINX 软件包仓库的软件包: apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...
2024/5/6 7:24:04 - Hive默认分割符、存储格式与数据压缩
目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限(ROW FORMAT)配置标准HQL为: ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...
2024/5/5 13:14:22 - 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法
文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中,传感器和控制器产生大量周…...
2024/5/6 7:24:03 - --max-old-space-size=8192报错
vue项目运行时,如果经常运行慢,崩溃停止服务,报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中,通过JavaScript使用内存时只能使用部分内存(64位系统&…...
2024/5/5 17:03:52 - 基于深度学习的恶意软件检测
恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞,例如可以被劫持的合法软件(例如浏览器或 Web 应用程序插件)中的错误。 恶意软件渗透可能会造成灾难性的后果,包括数据被盗、勒索或网…...
2024/5/5 21:10:50 - JS原型对象prototype
让我简单的为大家介绍一下原型对象prototype吧! 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定,每一个构造函数都有一个 prototype 属性,指向另一个对象,所以我们也称为原型对象…...
2024/5/6 7:24:02 - C++中只能有一个实例的单例类
C中只能有一个实例的单例类 前面讨论的 President 类很不错,但存在一个缺陷:无法禁止通过实例化多个对象来创建多名总统: President One, Two, Three; 由于复制构造函数是私有的,其中每个对象都是不可复制的,但您的目…...
2024/5/6 7:24:01 - python django 小程序图书借阅源码
开发工具: PyCharm,mysql5.7,微信开发者工具 技术说明: python django html 小程序 功能介绍: 用户端: 登录注册(含授权登录) 首页显示搜索图书,轮播图࿰…...
2024/5/5 17:03:21 - 电子学会C/C++编程等级考试2022年03月(一级)真题解析
C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...
2024/5/5 15:25:31 - 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...
解析如下:1、长按电脑电源键直至关机,然后再按一次电源健重启电脑,按F8健进入安全模式2、安全模式下进入Windows系统桌面后,按住“winR”打开运行窗口,输入“services.msc”打开服务设置3、在服务界面,选中…...
2022/11/19 21:17:18 - 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。
%读入6幅图像(每一幅图像的大小是564*564) f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...
2022/11/19 21:17:16 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...
win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面,在等待界面中我们需要等待操作结束才能关机,虽然这比较麻烦,但是对系统进行配置和升级…...
2022/11/19 21:17:15 - 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...
有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows,请勿关闭计算机”的提示,要过很久才能进入系统,有的用户甚至几个小时也无法进入,下面就教大家这个问题的解决方法。第一种方法:我们首先在左下角的“开始…...
2022/11/19 21:17:14 - win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...
置信有很多用户都跟小编一样遇到过这样的问题,电脑时发现开机屏幕显现“正在配置Windows Update,请勿关机”(如下图所示),而且还需求等大约5分钟才干进入系统。这是怎样回事呢?一切都是正常操作的,为什么开时机呈现“正…...
2022/11/19 21:17:13 - 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...
Win7系统开机启动时总是出现“配置Windows请勿关机”的提示,没过几秒后电脑自动重启,每次开机都这样无法进入系统,此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一:开机按下F8,在出现的Windows高级启动选…...
2022/11/19 21:17:12 - 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...
有不少windows10系统用户反映说碰到这样一个情况,就是电脑提示正在准备windows请勿关闭计算机,碰到这样的问题该怎么解决呢,现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法:1、2、依次…...
2022/11/19 21:17:11 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...
今天和大家分享一下win7系统重装了Win7旗舰版系统后,每次关机的时候桌面上都会显示一个“配置Windows Update的界面,提示请勿关闭计算机”,每次停留好几分钟才能正常关机,导致什么情况引起的呢?出现配置Windows Update…...
2022/11/19 21:17:10 - 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...
只能是等着,别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚,只能是考虑备份数据后重装系统了。解决来方案一:管理员运行cmd:net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...
2022/11/19 21:17:09 - 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?
原标题:电脑提示“配置Windows Update请勿关闭计算机”怎么办?win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢?一般的方…...
2022/11/19 21:17:08 - 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...
关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!关机提示 windows7 正在配…...
2022/11/19 21:17:05 - 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...
钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...
2022/11/19 21:17:05 - 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...
前几天班里有位学生电脑(windows 7系统)出问题了,具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面,长时间没反应,无法进入系统。这个问题原来帮其他同学也解决过,网上搜了不少资料&#x…...
2022/11/19 21:17:04 - 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...
本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法,并在最后教给你1种保护系统安全的好方法,一起来看看!电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中,添加了1个新功能在“磁…...
2022/11/19 21:17:03 - 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...
许多用户在长期不使用电脑的时候,开启电脑发现电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机。。.这要怎么办呢?下面小编就带着大家一起看看吧!如果能够正常进入系统,建议您暂时移…...
2022/11/19 21:17:02 - 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...
配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!配置windows update失败 还原更改 请勿关闭计算机&#x…...
2022/11/19 21:17:01 - 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...
不知道大家有没有遇到过这样的一个问题,就是我们的win7系统在关机的时候,总是喜欢显示“准备配置windows,请勿关机”这样的一个页面,没有什么大碍,但是如果一直等着的话就要两个小时甚至更久都关不了机,非常…...
2022/11/19 21:17:00 - 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...
当电脑出现正在准备配置windows请勿关闭计算机时,一般是您正对windows进行升级,但是这个要是长时间没有反应,我们不能再傻等下去了。可能是电脑出了别的问题了,来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...
2022/11/19 21:16:59 - 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...
我们使用电脑的过程中有时会遇到这种情况,当我们打开电脑之后,发现一直停留在一个界面:“配置Windows Update失败,还原更改请勿关闭计算机”,等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢࿰…...
2022/11/19 21:16:58 - 如何在iPhone上关闭“请勿打扰”
Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...
2022/11/19 21:16:57