首页 文章 精选 留言 我的

精选列表

搜索[java],共10000篇文章
优秀的个人博客,低调大师

spider-flow 0.2.0 发布,Java 开源爬虫平台

spider-flow 是一个无需写代码的爬虫平台,通过定义流程的方式制定爬虫 更新日志 新增全局变量功能 新增爬虫搜索功能 新增List打乱函数 新增内置demo(爬取开源中国动弹) 修复等待节点在双重循环中表现与预期不一致的BUG 修复某些Header无法设置的问题 修复循环次数可能不对的BUG 优化表格输出样式与高亮显示 优化表格输出tab页签名 演示站点 文档地址

优秀的个人博客,低调大师

spider-flow 0.1.0 发布,Java 开源爬虫平台

历时三个多月,第一个正式版发布 spider-flow 是一个无需写代码的爬虫平台,通过定义流程的方式制定爬虫 现已有特性如下: 支持css选择器、正则提取 支持JSON/XML格式 支持Xpath/JsonPath提取 支持多数据源、SQL select/insert/update/delete/批量插入 支持爬取JS动态渲染的页面 支持代理 支持二进制格式、二进制流格式 支持保存/读取文件(csv、xls、jpg等) 常用字符串、日期、文件、加解密等函数 支持流程嵌套 支持插件扩展(自定义执行器,自定义函数) 支持HTTP接口 已有插件如下: selenium 插件 redis 插件 mongodb 插件 IP代理池 插件 OCR 识别插件 OSS 插件 电子邮箱 插件 部分截图:

优秀的个人博客,低调大师

Java计算两个日期相差的月数

/** * 获取两个日期相差的月数 */ public static int getMonthDiff(Date d1, Date d2) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); int year1 = c1.get(Calendar.YEAR); int year2 = c2.get(Calendar.YEAR); int month1 = c1.get(Calendar.MONTH); int month2 = c2.get(Calendar.MONTH); int day1 = c1.get(Calendar.DAY_OF_MONTH); int day2 = c2.get(Calendar.DAY_OF_MONTH); // 获取年的差值 int yearInterval = year1 - year2; // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数 if (month1 < month2 || month1 == month2 && day1 < day2) { yearInterval--; } // 获取月数差值 int monthInterval = (month1 + 12) - month2; if (day1 < day2) { monthInterval--; } monthInterval %= 12; int monthsDiff = Math.abs(yearInterval * 12 + monthInterval); return monthsDiff; }

优秀的个人博客,低调大师

Java描述设计模式(07):适配器模式

本文源码:GitHub·点这里 || GitEE·点这里 一、适配器模式简介 1、基础概念 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作。适配器模式有类适配器模式和对象适配器模式,以及缺省(接口)适配器,三种不同的形式。 2、生活场景 基于适配器模式,把220V的电压,转换为需要的110V电压。 public class C01_InScene { public static void main(String[] args) { CurrentAdapter adapter = new CurrentAdapter() ; System.out.println(adapter.get110VCurrent()) ; } } // 220V电流 class Current220V { public int get220VCurrent (){ return 220 ; } } // 110V电流接口 interface Current110V { int get110VCurrent () ; } // 电流适配器 class CurrentAdapter extends Current220V implements Current110V { // 电流转换方法 @Override public int get110VCurrent() { int high = get220VCurrent() ; int low = high/2 ; return low ; } } 二、类适配器 1、模式简介 类的适配器模式把适配的类的API转换成为目标类的API。 2、核心角色 目标(Target)角色 这就是所期待得到的接口。 源(Adapee)角色: 现在需要适配的接口。 适配器(Adaper)角色 适配器类是本模式的核心。适配器把源接口转换成目标接口。 3、源码实现 interface Target { void sampleOperation1(); void sampleOperation2(); } class Adaptee { public void sampleOperation1(){ System.out.println("Adaptee.sampleOperation1()"); } } class Adapter extends Adaptee implements Target{ @Override public void sampleOperation2() { System.out.println("Adapter.sampleOperation2()"); } } 三、对象适配器 1、模式简介 与类的适配器模式一样,对象的适配器模式把被适配的类的API转换成为目标类的API,与类的适配器模式不同的是,对象的适配器模式不是使用继承关系连接到Adaptee类,而是使用委派关系连接到Adaptee类。 2、源码实现 interface Target1 { void sampleOperation1(); void sampleOperation2(); } class Adaptee1 { public void sampleOperation1(){ System.out.println("Adaptee.sampleOperation1()"); } } class Adapter1 implements Target1 { private Adaptee1 adaptee ; public Adapter1 (Adaptee1 adaptee){ this.adaptee = adaptee; } public void sampleOperation1() { this.adaptee.sampleOperation1(); } @Override public void sampleOperation2() { System.out.println("Adapter.sampleOperation2()"); } } 四、接口适配器 1、模式简介 缺省(接口)适配(Default Adapter)模式为一个接口提供缺省实现,这样子类型可以从这个缺省实现进行扩展,而不必从原有接口进行扩展。 2、源代码实现 public class C04_AdapterInte { public static void main(String[] args) { ServiceAdapter adapter = new ServiceAdapter(){ @Override public int serviceOperation2() { return 22 ; } }; System.out.println(adapter.serviceOperation2()); } } interface AbstractService { void serviceOperation1(); int serviceOperation2(); String serviceOperation3(); } class ServiceAdapter implements AbstractService{ @Override public void serviceOperation1() { } @Override public int serviceOperation2() { return 0; } @Override public String serviceOperation3() { return null; } } 五、Spring框架应用 1、应用场景描述 在SpringMvc执行控制执行请求的时候,有这样一个流程 1)前段控制器DispatcherServlet调用处理器适配器去执行Handler(也就是Controller);2)处理器适配器去执行Handler,给适配器返回ModelAndView ;3)处理器适配器向前端控制器返回ModelAndView ; 2、流程分析 核心接口和实现 Controller和HandlerAdapter两核心接口。 HandlerAdapter 适配器接口,使Handler有对应的适配器实现类,适配器代替Handler(控制层Controller)执行相应的方法。 public interface HandlerAdapter { // 判断类型是否匹配 boolean supports(Object var1); // 执行方法,返回ModelAndView ModelAndView handle(HttpServletRequest var1, HttpServletResponse var2, Object var3) throws Exception; } supports()方法传入处理器,判断适配器是否支持,如果支持则返回支持的适配器实现类。 DispatchServlert 抽取源码中体现流程的几个步骤。 protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { HandlerExecutionChain mappedHandler = null; mappedHandler = this.getHandler(processedRequest); HandlerAdapter ha = this.getHandlerAdapter(mappedHandler.getHandler()); mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); mappedHandler.applyPostHandle(processedRequest, response, mv); } SimpleControllerHandlerAdapter 最后看下supports和handle两个方法的具体实现。 public class SimpleControllerHandlerAdapter implements HandlerAdapter { public SimpleControllerHandlerAdapter() { } public boolean supports(Object handler) { return handler instanceof Controller; } public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return ((Controller)handler).handleRequest(request, response); } } 六、适配器优缺点 1、优点分析 更好的复用性,系统需要使用现有的类,而此类的接口不符合系统的需要。那么通过适配器模式就可以让这些功能得到更好的复用。更好的扩展性。 2、缺点分析 过多的使用适配器,会让系统非常零乱,不易整体进行把控。 七、源代码地址 GitHub·地址 https://github.com/cicadasmile/model-arithmetic-parent GitEE·地址 https://gitee.com/cicadasmile/model-arithmetic-parent

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

用户登录
用户注册