{"action":"created","comment":{"url":"https://api.github.com/repos/leancloud/docs/pulls/comments/81097395","pull_request_review_id":2101730,"id":81097395,"diff_hunk":"@@ -0,0 +1,132 @@\n+# LeanStorage 入门教程 &middot; {{platformName}}\n+\n+开发者们，你们好！本教程，将带你快速地理解和掌握 LeanCloud 的存储模块。我们会在示例项目的代码中，逐一地去熟悉几个核心的概念：`{{avUserName}}`、`{{avObjectName}}`、`{{avFileName}}`、`pointer`、`{{avQueryName}}` 和 `include`。即使你不熟悉数据库也没有关系，在理解了这些基础知识后，就可以开始基于 LeanCloud 的快速开发了。\n+\n+## 准备工作\n+* 选择下载你所需要的 [StorageStarted 源码](https://github.com/leancloud/StorageStarted)\n+\n+## 学习方式\n+ 1. 直接运行。你可以通过浏览 StorageStarted 的界面，同时查看 StorageStarted 里的代码，得到一个大体的印象。\n+ 2. [创建一个新应用](https://leancloud.cn/applist.html#/newapp)。找到项目里的初始化代码，替换为自己的 App ID 和 App Key，然后再次运行。\n+ 3. 通过对比 StorageStarted 里的代码，同时观察控制台的数据变化，来全面深入地理解 LeanStorage。\n+\n+## 开发步骤\n+### 使用 {{avUesrName}} 操作用户\n+\n+打开应用后，我们看到的是登录界面。我们先点击进入注册页面，注册一个用户。\n+\n+`{{avUesrName}}` 是用来描述一个用户的特殊对象，与之相关的数据都保存在 `_User` 数据表中。本质上，和下面所讲到的 `{{avObjectName}}` 是相同的。\n+\n+输入用户名、密码和邮箱后，通过如下代码完成注册过程；成功后，在你的控制台的 `_User` 表里，会对应地生成一条数据，也就是刚刚注册成功的这名用户：\n+\n+```java\n+    AVUser user = new AVUser();// 新建 AVUser 对象实例\n+    user.setUsername(username);// 设置用户名\n+    user.setPassword(password);// 设置密码\n+    user.setEmail(email);//设置邮箱\n+    user.signUpInBackground(new SignUpCallback() {\n+      @Override\n+      public void done(AVException e) {\n+        if (e == null) {\n+          // 注册成功，把用户对象赋值给当前用户 AVUser.getCurrentUser()\n+          startActivity(new Intent(RegisterActivity.this, MainActivity.class));\n+          RegisterActivity.this.finish();\n+        } else {\n+          // 失败的原因可能有多种，常见的是用户名已经存在。\n+          showProgress(false);\n+          Toast.makeText(RegisterActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();\n+        }\n+      }\n+    });\n+```\n+\n+如果已有帐号，那就在登录页面，通过以下代码完成登录操作：\n+\n+```java\n+    AVUser.logInInBackground(username, password, new LogInCallback<AVUser>() {\n+      @Override\n+      public void done(AVUser avUser, AVException e) {\n+        if (e == null) {\n+          LoginActivity.this.finish();\n+          startActivity(new Intent(LoginActivity.this, MainActivity.class));\n+        } else {\n+          showProgress(false);\n+          Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();\n+        }\n+      }\n+    });\n+```\n+\n+### 使用 {{avObjectName}} 新增数据\n+\n+登录成功后，我们进入主页面。如果主页面没有任何内容，我们则点击进入发布页面，来发布一个新商品。\n+\n+`{{avObjectName}}` 是 LeanStorage 对复杂对象的封装，每个 `{{avObjectName}}` 包含若干属性值对，也称键值对（key-value）。\n+\n+`pointer`，本质上是指向另外一张表的指针。在下面这个案例里，`owner` 字段，就是 `Product` 表里，用来指向 `_User` 表的一名用户的指针。\n+\n+`{{avFileName}}` 是用来描述一个文件的特殊对象，与之相关的数据都保存在 `_File` 数据表中。\n+\n+依次输入标题、商品描述和金额，并从相册挑选一张商品图片后，通过如下代码完成发布过程；成功后，在你的控制台里会新增一张名为 `Product` 的表，表里有一条新数据，也就是刚刚发布成功的这条数据：\n+\n+```java\n+    AVObject product = new AVObject(\"Product\");\n+    product.put(\"title\", mTitleEdit.getText().toString());\n+    product.put(\"description\", mDiscriptionEdit.getText().toString());\n+    product.put(\"price\", Integer.parseInt(mPriceEdit.getText().toString()));\n+    product.put(\"owner\", AVUser.getCurrentUser());\n+    product.put(\"image\", new AVFile(\"productPic\", mImageBytes));\n+    product.saveInBackground(new SaveCallback() {\n+      @Override\n+      public void done(AVException e) {\n+        if (e == null) {\n+          mProgerss.setVisibility(View.GONE);\n+          PublishActivity.this.finish();\n+        } else {\n+          mProgerss.setVisibility(View.GONE);\n+          Toast.makeText(PublishActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();\n+        }\n+      }\n+    });\n+```\n+\n+### 使用 {{avQueryName}} 进行查询\n+\n+发布成功后，我们回到主页面。对 `Product` 表进行查询。\n+\n+`{{avQueryName}}` 是构建针对 `{{avObjectName}}` 查询的基础类。\n+\n+还记得前面提到的 `pointer`？`Product` 表里的 `owner` 字段，就是一个 `pointer` 型字段，它仅包含 3 个键值对的信息，数据形式为：\n+\n+```\n+  \"owner\": {\n+    \"__type\": \"Pointer\",\n+    \"className\": \"_User\",\n+    \"objectId\": \"57e264c667f3560056c3cb1e\"\n+  },\n+```\n+\n+而如果想在查询 `Product` 表时，同时获取到 `_User` 表的其它字段信息呢？这样的话，就需要用到 `include` 关键字。\n+\n+请看示例，通过如下代码实现查询过程：\n+\n+```java\n+    AVQuery<AVObject> avQuery = new AVQuery<>(\"Product\");\n+    avQuery.orderByDescending(\"createdAt\");\n+    avQuery.include(\"owner\");\n+    avQuery.findInBackground(new FindCallback<AVObject>() {\n+      @Override\n+      public void done(List<AVObject> list, AVException e) {\n+        if (e == null) {\n+          mList.addAll(list);\n+          mRecyclerAdapter.notifyDataSetChanged();\n+        } else {\n+          e.printStackTrace();\n+        }\n+      }\n+    });\n+```\n+\n+##  更进一步\n+\n+如果你之后，在存储模块的开发过程中，遇到任何问题，请直接查阅以下文档的相关部分：{{link_to_storage_guide_doc}}。","path":"views/leanstorage_started.tmpl","position":132,"original_position":132,"commit_id":"2483b5b8f0cf2d8452a2f2b0400e39ab7ec9e469","original_commit_id":"2483b5b8f0cf2d8452a2f2b0400e39ab7ec9e469","user":{"login":"BinaryHB","id":6046086,"avatar_url":"https://avatars.githubusercontent.com/u/6046086?v=3","gravatar_id":"","url":"https://api.github.com/users/BinaryHB","html_url":"https://github.com/BinaryHB","followers_url":"https://api.github.com/users/BinaryHB/followers","following_url":"https://api.github.com/users/BinaryHB/following{/other_user}","gists_url":"https://api.github.com/users/BinaryHB/gists{/gist_id}","starred_url":"https://api.github.com/users/BinaryHB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BinaryHB/subscriptions","organizations_url":"https://api.github.com/users/BinaryHB/orgs","repos_url":"https://api.github.com/users/BinaryHB/repos","events_url":"https://api.github.com/users/BinaryHB/events{/privacy}","received_events_url":"https://api.github.com/users/BinaryHB/received_events","type":"User","site_admin":false},"body":"不好放哪里，干脆去掉了。","created_at":"2016-09-29T09:28:57Z","updated_at":"2016-09-29T09:28:57Z","html_url":"https://github.com/leancloud/docs/pull/1568#discussion_r81097395","pull_request_url":"https://api.github.com/repos/leancloud/docs/pulls/1568","_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments/81097395"},"html":{"href":"https://github.com/leancloud/docs/pull/1568#discussion_r81097395"},"pull_request":{"href":"https://api.github.com/repos/leancloud/docs/pulls/1568"}}},"pull_request":{"url":"https://api.github.com/repos/leancloud/docs/pulls/1568","id":86471263,"html_url":"https://github.com/leancloud/docs/pull/1568","diff_url":"https://github.com/leancloud/docs/pull/1568.diff","patch_url":"https://github.com/leancloud/docs/pull/1568.patch","issue_url":"https://api.github.com/repos/leancloud/docs/issues/1568","number":1568,"state":"open","locked":false,"title":"complete storage demo guide doc","user":{"login":"BinaryHB","id":6046086,"avatar_url":"https://avatars.githubusercontent.com/u/6046086?v=3","gravatar_id":"","url":"https://api.github.com/users/BinaryHB","html_url":"https://github.com/BinaryHB","followers_url":"https://api.github.com/users/BinaryHB/followers","following_url":"https://api.github.com/users/BinaryHB/following{/other_user}","gists_url":"https://api.github.com/users/BinaryHB/gists{/gist_id}","starred_url":"https://api.github.com/users/BinaryHB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BinaryHB/subscriptions","organizations_url":"https://api.github.com/users/BinaryHB/orgs","repos_url":"https://api.github.com/users/BinaryHB/repos","events_url":"https://api.github.com/users/BinaryHB/events{/privacy}","received_events_url":"https://api.github.com/users/BinaryHB/received_events","type":"User","site_admin":false},"body":"希望 review 下：\r\n1、个人觉得部分文字口语化，不够书面，但又不知道如何改。请指出来，我来校正；\r\n2、代码片段，暂时只贴了 Android 作为示例，会和云引擎里的代码一样，做成 tab 切换。\r\n\r\n待确认的事情：\r\n1、这个教程的文档，在上线后应该放置在什么位置，需要 @jwfing 定夺。","created_at":"2016-09-23T08:18:38Z","updated_at":"2016-09-29T09:28:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"68825119d1817a54227df6dc09576aa14d80e7b2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/leancloud/docs/pulls/1568/commits","review_comments_url":"https://api.github.com/repos/leancloud/docs/pulls/1568/comments","review_comment_url":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/leancloud/docs/issues/1568/comments","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/2483b5b8f0cf2d8452a2f2b0400e39ab7ec9e469","head":{"label":"BinaryHB:add_storage_started","ref":"add_storage_started","sha":"2483b5b8f0cf2d8452a2f2b0400e39ab7ec9e469","user":{"login":"BinaryHB","id":6046086,"avatar_url":"https://avatars.githubusercontent.com/u/6046086?v=3","gravatar_id":"","url":"https://api.github.com/users/BinaryHB","html_url":"https://github.com/BinaryHB","followers_url":"https://api.github.com/users/BinaryHB/followers","following_url":"https://api.github.com/users/BinaryHB/following{/other_user}","gists_url":"https://api.github.com/users/BinaryHB/gists{/gist_id}","starred_url":"https://api.github.com/users/BinaryHB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BinaryHB/subscriptions","organizations_url":"https://api.github.com/users/BinaryHB/orgs","repos_url":"https://api.github.com/users/BinaryHB/repos","events_url":"https://api.github.com/users/BinaryHB/events{/privacy}","received_events_url":"https://api.github.com/users/BinaryHB/received_events","type":"User","site_admin":false},"repo":{"id":53110578,"name":"docs","full_name":"BinaryHB/docs","owner":{"login":"BinaryHB","id":6046086,"avatar_url":"https://avatars.githubusercontent.com/u/6046086?v=3","gravatar_id":"","url":"https://api.github.com/users/BinaryHB","html_url":"https://github.com/BinaryHB","followers_url":"https://api.github.com/users/BinaryHB/followers","following_url":"https://api.github.com/users/BinaryHB/following{/other_user}","gists_url":"https://api.github.com/users/BinaryHB/gists{/gist_id}","starred_url":"https://api.github.com/users/BinaryHB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BinaryHB/subscriptions","organizations_url":"https://api.github.com/users/BinaryHB/orgs","repos_url":"https://api.github.com/users/BinaryHB/repos","events_url":"https://api.github.com/users/BinaryHB/events{/privacy}","received_events_url":"https://api.github.com/users/BinaryHB/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/BinaryHB/docs","description":"LeanCloud Documentation","fork":true,"url":"https://api.github.com/repos/BinaryHB/docs","forks_url":"https://api.github.com/repos/BinaryHB/docs/forks","keys_url":"https://api.github.com/repos/BinaryHB/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BinaryHB/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BinaryHB/docs/teams","hooks_url":"https://api.github.com/repos/BinaryHB/docs/hooks","issue_events_url":"https://api.github.com/repos/BinaryHB/docs/issues/events{/number}","events_url":"https://api.github.com/repos/BinaryHB/docs/events","assignees_url":"https://api.github.com/repos/BinaryHB/docs/assignees{/user}","branches_url":"https://api.github.com/repos/BinaryHB/docs/branches{/branch}","tags_url":"https://api.github.com/repos/BinaryHB/docs/tags","blobs_url":"https://api.github.com/repos/BinaryHB/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BinaryHB/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BinaryHB/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/BinaryHB/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BinaryHB/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/BinaryHB/docs/languages","stargazers_url":"https://api.github.com/repos/BinaryHB/docs/stargazers","contributors_url":"https://api.github.com/repos/BinaryHB/docs/contributors","subscribers_url":"https://api.github.com/repos/BinaryHB/docs/subscribers","subscription_url":"https://api.github.com/repos/BinaryHB/docs/subscription","commits_url":"https://api.github.com/repos/BinaryHB/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/BinaryHB/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/BinaryHB/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/BinaryHB/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/BinaryHB/docs/contents/{+path}","compare_url":"https://api.github.com/repos/BinaryHB/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BinaryHB/docs/merges","archive_url":"https://api.github.com/repos/BinaryHB/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BinaryHB/docs/downloads","issues_url":"https://api.github.com/repos/BinaryHB/docs/issues{/number}","pulls_url":"https://api.github.com/repos/BinaryHB/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/BinaryHB/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/BinaryHB/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BinaryHB/docs/labels{/name}","releases_url":"https://api.github.com/repos/BinaryHB/docs/releases{/id}","deployments_url":"https://api.github.com/repos/BinaryHB/docs/deployments","created_at":"2016-03-04T05:42:29Z","updated_at":"2016-03-04T05:42:31Z","pushed_at":"2016-09-29T08:21:50Z","git_url":"git://github.com/BinaryHB/docs.git","ssh_url":"git@github.com:BinaryHB/docs.git","clone_url":"https://github.com/BinaryHB/docs.git","svn_url":"https://github.com/BinaryHB/docs","homepage":"http://leancloud.cn/docs/","size":41053,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"leancloud:master","ref":"master","sha":"9836ba906f0bb4f65314f94182cad89b0a09d023","user":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"repo":{"id":25067518,"name":"docs","full_name":"leancloud/docs","owner":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/leancloud/docs","description":"LeanCloud Documentation","fork":false,"url":"https://api.github.com/repos/leancloud/docs","forks_url":"https://api.github.com/repos/leancloud/docs/forks","keys_url":"https://api.github.com/repos/leancloud/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leancloud/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leancloud/docs/teams","hooks_url":"https://api.github.com/repos/leancloud/docs/hooks","issue_events_url":"https://api.github.com/repos/leancloud/docs/issues/events{/number}","events_url":"https://api.github.com/repos/leancloud/docs/events","assignees_url":"https://api.github.com/repos/leancloud/docs/assignees{/user}","branches_url":"https://api.github.com/repos/leancloud/docs/branches{/branch}","tags_url":"https://api.github.com/repos/leancloud/docs/tags","blobs_url":"https://api.github.com/repos/leancloud/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leancloud/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leancloud/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/leancloud/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/leancloud/docs/languages","stargazers_url":"https://api.github.com/repos/leancloud/docs/stargazers","contributors_url":"https://api.github.com/repos/leancloud/docs/contributors","subscribers_url":"https://api.github.com/repos/leancloud/docs/subscribers","subscription_url":"https://api.github.com/repos/leancloud/docs/subscription","commits_url":"https://api.github.com/repos/leancloud/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/leancloud/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/leancloud/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/leancloud/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/leancloud/docs/contents/{+path}","compare_url":"https://api.github.com/repos/leancloud/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leancloud/docs/merges","archive_url":"https://api.github.com/repos/leancloud/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leancloud/docs/downloads","issues_url":"https://api.github.com/repos/leancloud/docs/issues{/number}","pulls_url":"https://api.github.com/repos/leancloud/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/leancloud/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/leancloud/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leancloud/docs/labels{/name}","releases_url":"https://api.github.com/repos/leancloud/docs/releases{/id}","deployments_url":"https://api.github.com/repos/leancloud/docs/deployments","created_at":"2014-10-11T07:14:37Z","updated_at":"2016-09-29T00:38:25Z","pushed_at":"2016-09-29T08:41:18Z","git_url":"git://github.com/leancloud/docs.git","ssh_url":"git@github.com:leancloud/docs.git","clone_url":"https://github.com/leancloud/docs.git","svn_url":"https://github.com/leancloud/docs","homepage":"https://leancloud.cn/docs/","size":44451,"stargazers_count":319,"watchers_count":319,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":183,"mirror_url":null,"open_issues_count":82,"forks":183,"open_issues":82,"watchers":319,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/1568"},"html":{"href":"https://github.com/leancloud/docs/pull/1568"},"issue":{"href":"https://api.github.com/repos/leancloud/docs/issues/1568"},"comments":{"href":"https://api.github.com/repos/leancloud/docs/issues/1568/comments"},"review_comments":{"href":"https://api.github.com/repos/leancloud/docs/pulls/1568/comments"},"review_comment":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/leancloud/docs/pulls/1568/commits"},"statuses":{"href":"https://api.github.com/repos/leancloud/docs/statuses/2483b5b8f0cf2d8452a2f2b0400e39ab7ec9e469"}}}}
{"actor":{"display_login":"BinaryHB"}}