1 Star 1 Fork 1

hmfdev/JavaLearn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

JavaLearn

介绍

Java各个知识点学习Demo,每个知识点对应一个Module
1.RabbitMQ
2.SpringAMQP
3.FastDFS
4.Swagger、SwaggerWithUI
5.Jsoup
6.Excel表的读写

提交日志细节记录

  1. 【1.本地初始化】
    1)IDEA中使用 Spring Initializr 创建一个SpringBoot项目
    2)使用git clone gitee版本库中新建的repository项目到本地,加入clone下来的内容到新建的SpringBoot项目中,整合后删除一些不需要的文件后,做本地初始化提交
    3)我把IDEA生成的.gitignore和gitee中clone下来的.gitignore合并到一起

  2. 【2.RabbitMQ-demo-简单队列】
    1)代码里有一个消息生成者类Send和消息消费者类Recv,代码里要设置连接rabbitmq的内容,如登录名、密码等
    2)simple文件夹里就是简单队列

  3. 【3.RabbitMQ-demo-工作队列(轮询)】
    1)在work/rr文件夹下
    2)工作队列(轮询)解决的问题:生产者的生产能力远远大于消费者的消费能力的时候,我们加多几个消费者
    3)轮询有缺点

  4. 【4.RabbitMQ-demo-工作队列(公平)】
    1)在work/fair文件夹下
    2)在接受者中加个限流的代码即可,做到能者多劳,处理完成才能消费下一条消息
    3)模拟消费耗时Rece01是1秒,Rece02是2秒

  5. 【5.RabbitMQ-demo-发布-订阅队列】
    1)现在就是要定义交换机了
    2)消息发给交换机,由交换机转发到绑定的队列,消费者从绑定的队列中取

  6. 【6.RabbitMQ-demo-路由队列】
    1)把原来的exchanges包名修改为了fanout,因为是通过交换机来命名
    2)包名是fanout为发布/订阅队列,包名是direct为路由队列
    3)加了路由key,通过路由key去绑定不同的队列,然后发消息的时候要携带这个路由key,根据这个路由key去交换机找到它所绑定的队列,然后才把消息发到这个队列
    4)不指定交换,默认走的是(AMQP default) 交换机,Type是direct,在rabbitmq管理界面的Exchanges选项卡中
    5)路由队列的缺点:当项目越来越庞大,使用的路由key越来越多的时候,不容易去管理

  7. 【7.RabbitMQ-demo-主题队列(工作中最常用)】
    1)加通配符 * 或 #,*只能匹配一个,#可以匹配0个或多个,模糊匹配管理,尽量减少路由key的编写
    2)发送消息是详细的路由key,绑定的时候才是通配符,根据详细的路由key去通配符里匹配,匹配到就发送,匹配不到就丢弃
    3)为什么说在工作中常用这个模式,因为通过这个模式可以实现其他的几种模式

  8. 【8.RabbitMQ-demo-RPC队列(很少用到)】
    1)直接从文档copy代码了
    2)测试时,先启动 RPCServer,不然会报错
    3)了解RabbitMQ官网RPC模式队列的图就行了

  9. 【9.更新readme】

  10. 【10.RabbitMQ-demo-事物】
    1)使用channel.txSelect();开启事物,使用channel.txCommit();提交事物
    2)一般很少去使用事物,因为使用了事物就会降低RabbitMQ的性能

  11. 【11.RabbitMQ-demo-同步确认模式】
    1)同步确认模式有缺点,所以我们一般都是用下面讲到的异步确认模式

  12. 【12.RabbitMQ-demo-异步确认模式】
    1)什么叫异步:你发消息,我这边等确认,确认的同时,我任然能发消息,然后这个时候队列确认消息的时候返回,返回的时候我的生成者有一个回调的方法,能够收到你返回的消息进行相应的处理
    2)特别要注意异步的编程还是比较复杂的
    3)异步确认模式最重要的就是 监听回调

  13. 【13.SpringAMQP-demo-Spring AMQP】
    1)spring AMQP说白了也就是spring对AMQP模板的封装,在官网 https://spring.io/projects/spring-amqp 可以查看
    2)新建springampq-demo的Module
    3)然后再新建两个Module,一个是消息的生产者amqp-send,一个是消息的消费者amqp-recv
    4)然后配置pom.xml文件,包括父工程的指定,子工程的指定,不过子工程一般会在新建时自动指定
    5)创建两个Module,amqp-send 和 amqp-recv,并配置pom.xml和application.yml文件后,前期的搭建就算完成了
    6)RabbitMQ需要一个交换机,一个队列,还有交换机和队列做绑定
    7)Queue类导入的是import org.springframework.amqp.core.Queue;
    8)在测试类中发送消息测试,测试类需要在类上加注解@SpringBootTest,在方法上加注解@Test
    9)通过 RabbitTemplate 发送消息
    10)总结(主要三点):
       1.通过配置类RabbitMQConfig配置队列、交换机、绑定,绑定的时候带上路由key;
       2.正常发消息是通过RabbitTemplate的convertAndSend()方法带上交换机和路由key和还有消息发送消息;
       3.监听者只需要准备两个注解@RabbitListener和@RabbitHandler

  14. 【14.fastdfs-demo-Demo环境初始化】
    1)这里存在一个FastDFS依赖导入不成功的问题,解决办法 http://www.qishunwang.net/knowledge_show_129043.aspx
    2)新建fdfs_client.conf文件,用来初始化;其中tracker的ip要改为你的tracker服务ip
    3)新建一个文件上传对象类 FastDFSFile 类
    4)新建一个工具类FastDFSClient,用来生成Tracker服务器端、生成Storage客户端、上传文件、下载文件等

  15. 【15.fastdfs-demo-FastDFS文件工具类】
    1)工具类体提供的方法有:上传文件、下载文件、删除文件、查看文件信息、获取文件路径

  16. 【16.fastdfs-demo-文件上传】
    1)正常情况下是service层调用我们工具类里的上传等方法,然后controller再去调用service层,但我们这里只是演示,就只有controller层了
    2)Controller层中重定向的写法 return "redirect:uploadStatus"; 后面 uploadStatus是Controller方法的请求的路径
    3)这里有两个页面:upload.html、uploadStatus.html
    4)注意上传的文件大小需要配置,如果文件过大就上传不成功了
    5)文件上传测试成功

  17. 【17.swagger-demo-最简单的swagger接口文档搭建】
    1)导入swagger所需的两个依赖 springfox-swagger2、springfox-swagger-ui,其中第二个依赖是swagger的页面依赖,提供了可视化的页面 2)然后是swagger配置类 SwaggerConfig 的配置,其中.apis(RequestHandlerSelectors.basePackage("com.xxxx.swagger.controller"),需要放上你的controller层的路径,以便swagger扫描展示
    3)swagger的注解常用的主要分为两类:
    第一类是用在实体类上的注解(有两个)--如这里的User类, @ApiModel(用在实体类上)、 @ApiModelPropert(用在实体类的字段上);
    第二类是用在controller层中xxxxController类中的注解(有三个)--如这里的HelloController类, @Api(用在controller类上)、 @ApiOperation(用在controller方法上,说明该方法的作用,如增删改查等)、 @ApiParam(用在controller方法的参数上,说明该参数的作用)
    4)这里还说明了多环境是application的使用,以及使用 @Value 注解直接获取配置文件中的数据,还可以自定义参数到配置文件中,然后通过 @Value 注解去直接获取,并绑定到定义的字段变量中
    5)原始swagger接口文档访问地址:http://localhost:8080/swagger-ui.html

  18. 【18.swaggerWithUi-demo-第三方带有不同UI界面的swagger接口文档搭建】
    1)导入swagger所需的两个依赖 springfox-swagger2、swagger-bootstrap-ui,其中第二个依赖是第三方swagger的页面依赖,提供了可视化的页面
    2)然后是swagger配置类 Swagger2Config 的配置,其中.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller")),需要放上你的controller层的路径,以便swagger扫描展示
    3)swagger的注解常用的主要分为两类:
    第一类是用在实体类上的注解(有两个)--如这里的User类, @ApiModel(用在实体类上)、 @ApiModelPropert(用在实体类的字段上);
    第二类是用在controller层中xxxxController类中的注解(有三个)--如这里的HelloController类, @Api(用在controller类上)、 @ApiOperation(用在controller方法上,说明该方法的作用,如增删改查等)、 @ApiParam(用在controller方法的参数上,说明该参数的作用)
    4)第三方swagger接口文档访问地址:http://localhost:8080/doc.html

  19. 【19.jsoup-demo-使用jsoup实现Java简单爬虫(爬取图片)】
    1)使用maven项目,引入jsoup依赖坐标,我使用的版本是 1.13.1
    2)代码写在了 JsoupSpider 类中,运行该类的 main() 方法即可看到效果
    3)在有些反爬虫的网站中使用该方法,可能会失效
    4)使用输入输出流,把图片保存到本地磁盘中

  20. 【20.jsoup-kuang-demo-使用jsoup实现Java简单爬虫(爬取京东数据)(1)】
    1)要使用jsoup,当然要引入jsoup的依赖坐标,需要爬取音频、视频数据时需要用到 tika 包
    2)该demo来自狂神视频,语句后面加 .var 可以快速定时该语句返回的变量
    3)步骤要点总结:1.请求的url地址 2.分析网页 3.找到目标数据的父节点 div 4.再通过获取到的div,一层一层的获取,直到获取到目标数据
    4)重点是要分析 html 页面的结构,以帮助我们更好的获取到目标的数据
    5)到这里我们就获取到的指定的目标价格了
    6)可以把页面元素copy下来放到webStorm里分析里面的元素,编译取到目标资源
    7)HtmlParseUtil 类爬虫代码基本完成
    8)HtmlParseUtilTest 类用于测试时使用

  21. 【21.jsoup-kuang-demo-使用jsoup实现Java简单爬虫(爬取京东数据)(2)】
    1)可以把页面元素copy下来放到webStorm里分析里面的元素,编译取到目标资源
    2)这里还涉及到一个懒加载的知识
    3)HtmlParseUtil 类爬虫代码基本完成
    4)HtmlParseUtilTest 类用于测试时使用

  22. 【22.jsoup-kuang-demo-使用jsoup实现Java简单爬虫(爬取京东数据)-- 加入获取数据的关键流程(3)】
    1)测试类中加关键获取流程代码,搜索(关键获取流程)即可找到,这里需要熟悉Jsoup中获取元素的方法

  23. 【23.jsoup-kuang-demo-使用jsoup实现Java简单爬虫(爬取京东数据)-- 获取京东书名、价格、图片链接完成(4)】
    1)获取京东书名、价格、图片链接完成,突破点是用 first() 方法来获取第一个元素
    2)总结:看Jsoup Api文档了解各个主要方法的使用很重要,也可以直接在IDEA上查看该方法的文档注释英文说明

  24. 【24.Java学爬虫仔细研究这里提交的内容就行了】
    1)如果页面请求接口返回的是 json 数据,分两种情况:
    1.表单提交类型是 Request Payload,模拟浏览器请求就需要 加上 Request Payload 的表单提交数据
    2.表单提交类型是 Form Data, 模拟浏览器请求就需要在 请求地址栏 后面 加上 Form Data 的表单提交数据
    2)如果没有接口返回数据,而是服务器把数据加到页面后,再返回给浏览器,这时返回的是 html 文档内容,需要使用 JSoup 分析页面,并提取出有用的数据
    3)Json数据的解析需要用到 fastJson 解析工具

  25. 【25.爬取某个网站数据的工具类】
    1)工具类分为 获取列表数据、获取页面详细数据、综合工具类

  26. 【26.Excel表的读写】
    1)首先引入 apache 的 poi 坐标依赖,版本是 4.1.2
    2)ExcelWriteDemo 数据写到Excel表,并把Excel表保存到本地磁盘中
    3)ExcelWriteDemoPlus 模拟数据库返回的List数据,写入到Excel表中,并保存到本地磁盘中
    4)ExcelReadDemo 读取Excel表中的数据,通过转换成入库实体类对象后,可以批量入库
    5)导入导出的方法写在对应service实现层中

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Java各个知识点学习Demo,每个知识点对应一个Module 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/hmfdev/JavaLearn.git
git@gitee.com:hmfdev/JavaLearn.git
hmfdev
JavaLearn
JavaLearn
master

搜索帮助