极光推送指定用户推送_干货|SpringBoot集成极光推送完整实现代码(建议收藏)...

工作中经常会遇到服务器向App推送消息的需求,一般企业中选择用极光推送的比较多,在集成极光时发现极光的文档并不完整,网上的文章也很多不能直接使用,这里列出我在工作中集成极光的全部代码,只需要按照如下代码保证一次性实现。

17de46ee8f7e43a3eff92deee9b4a96e.png

1.pom.xml

cn.jpush.api    jpush-client    3.3.10cn.jpush.api    jiguang-common    1.1.4

2.application.yml

jpush:  appKey: xxx  masterSecret: xxxx  apnsProduction: false   # 是否生成环境,true表示生成环境

3.MyJPushClient

import cn.jiguang.common.resp.APIConnectionException;import cn.jiguang.common.resp.APIRequestException;import cn.jpush.api.JPushClient;import cn.jpush.api.push.PushResult;import cn.jpush.api.push.model.Message;import cn.jpush.api.push.model.Options;import cn.jpush.api.push.model.Platform;import cn.jpush.api.push.model.PushPayload;import cn.jpush.api.push.model.audience.Audience;import cn.jpush.api.push.model.notification.AndroidNotification;import cn.jpush.api.push.model.notification.IosNotification;import cn.jpush.api.push.model.notification.Notification;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;import java.util.List;/** * 极光推送客户端 * * @author Mengday Zhang * @version 1.0 * @since 2019-04-01 */@Componentpublic class MyJPushClient {    @Value("${jpush.appKey}")    private String appKey;    @Value("${jpush.masterSecret}")    private String masterSecret;    @Value("${jpush.apnsProduction}")    private boolean apnsProduction;    private static JPushClient jPushClient = null;    private static final int RESPONSE_OK = 200;    private static final Logger logger = LoggerFactory.getLogger(MyJPushClient.class);    public JPushClient getJPushClient() {        if (jPushClient == null) {            jPushClient = new JPushClient(masterSecret, appKey);        }        return jPushClient;    }    /**     * 推送到alias列表     *     * @param alias             别名或别名组     * @param notificationTitle 通知内容标题     * @param msgTitle          消息内容标题     * @param msgContent        消息内容     * @param extras            扩展字段     */    public void sendToAliasList(List alias, String notificationTitle, String msgTitle, String msgContent, String extras) {        PushPayload pushPayload = buildPushObject_all_aliasList_alertWithTitle(alias, notificationTitle, msgTitle, msgContent, extras);        this.sendPush(pushPayload);    }    /**     * 推送到tag列表     *     * @param tagsList          Tag或Tag组     * @param notificationTitle 通知内容标题     * @param msgTitle          消息内容标题     * @param msgContent        消息内容     * @param extras            扩展字段     */    public void sendToTagsList(List tagsList, String notificationTitle, String msgTitle, String msgContent, String extras) {        PushPayload pushPayload = buildPushObject_all_tagList_alertWithTitle(tagsList, notificationTitle, msgTitle, msgContent, extras);        this.sendPush(pushPayload);    }    /**     * 发送给所有安卓用户     *     * @param notificationTitle 通知内容标题     * @param msgTitle          消息内容标题     * @param msgContent        消息内容     * @param extras        扩展字段     */    public void sendToAllAndroid(String notificationTitle, String msgTitle, String msgContent, String extras) {        PushPayload pushPayload = buildPushObject_android_all_alertWithTitle(notificationTitle, msgTitle, msgContent, extras);        this.sendPush(pushPayload);    }    /**     * 发送给所有IOS用户     *     * @param notificationTitle 通知内容标题     * @param msgTitle          消息内容标题     * @param msgContent        消息内容     * @param extras        扩展字段     */    public void sendToAllIOS(String notificationTitle, String msgTitle, String msgContent, String extras) {        PushPayload pushPayload = buildPushObject_ios_all_alertWithTitle(notificationTitle, msgTitle, msgContent, extras);        this.sendPush(pushPayload);    }    /**     * 发送给所有用户     *     * @param notificationTitle 通知内容标题     * @param msgTitle          消息内容标题     * @param msgContent        消息内容     * @param extras        扩展字段     */    public void sendToAll(String notificationTitle, String msgTitle, String msgContent, String extras) {        PushPayload pushPayload = buildPushObject_android_and_ios(notificationTitle, msgTitle, msgContent, extras);        this.sendPush(pushPayload);    }    private PushResult sendPush(PushPayload pushPayload) {        logger.info("pushPayload={}", pushPayload);        PushResult pushResult = null;        try {            pushResult = this.getJPushClient().sendPush(pushPayload);            logger.info("" + pushResult);            if (pushResult.getResponseCode() == RESPONSE_OK) {                logger.info("push successful, pushPayload={}", pushPayload);            }        } catch (APIConnectionException e) {            logger.error("push failed: pushPayload={}, exception={}", pushPayload, e);        } catch (APIRequestException e) {            logger.error("push failed: pushPayload={}, exception={}", pushPayload, e);        }        return pushResult;    }    /**     * 向所有平台所有用户推送消息     *     * @param notificationTitle     * @param msgTitle     * @param msgContent     * @param extras     * @return     */    public PushPayload buildPushObject_android_and_ios(String notificationTitle, String msgTitle, String msgContent, String extras) {        return PushPayload.newBuilder()                .setPlatform(Platform.android_ios())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .setAlert(notificationTitle)                        .addPlatformNotification(AndroidNotification.newBuilder()                                .setAlert(notificationTitle)                                .setTitle(notificationTitle)                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("androidNotification extras key", extras)                                .build()                        )                        .addPlatformNotification(IosNotification.newBuilder()                                // 传一个IosAlert对象,指定apns title、title、subtitle等                                .setAlert(notificationTitle)                                // 直接传alert                                // 此项是指定此推送的badge自动加1                                .incrBadge(1)                                // 此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音                                .setSound("default")                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("iosNotification extras key", extras)                                // 此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification                                // .setContentAvailable(true)                                .build()                        )                        .build()                )                // Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别                .setMessage(Message.newBuilder()                        .setMsgContent(msgContent)                        .setTitle(msgTitle)                        .addExtra("message extras key", extras)                        .build())                .setOptions(Options.newBuilder()                        // 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义                        .setApnsProduction(apnsProduction)                        // 此字段是给开发者自己给推送编号,方便推送者分辨推送记录                        .setSendno(1)                        // 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒                        .setTimeToLive(86400)                        .build())                .build();    }    /**     * 向所有平台单个或多个指定别名用户推送消息     *     * @param aliasList     * @param notificationTitle     * @param msgTitle     * @param msgContent     * @param extras     * @return     */    private PushPayload buildPushObject_all_aliasList_alertWithTitle(List aliasList, String notificationTitle, String msgTitle, String msgContent, String extras) {        // 创建一个IosAlert对象,可指定APNs的alert、title等字段        // IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody("title", "alert body").build();        return PushPayload.newBuilder()                // 指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台                .setPlatform(Platform.all())                // 指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id                .setAudience(Audience.alias(aliasList))                // jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发                .setNotification(Notification.newBuilder()                        // 指定当前推送的android通知                        .addPlatformNotification(AndroidNotification.newBuilder()                                .setAlert(notificationTitle)                                .setTitle(notificationTitle)                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("androidNotification extras key", extras)                                .build())                        // 指定当前推送的iOS通知                        .addPlatformNotification(IosNotification.newBuilder()                                // 传一个IosAlert对象,指定apns title、title、subtitle等                                .setAlert(notificationTitle)                                // 直接传alert                                // 此项是指定此推送的badge自动加1                                .incrBadge(1)                                // 此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音                                .setSound("default")                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("iosNotification extras key", extras)                                // 此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification                                // 取消此注释,消息推送时ios将无法在锁屏情况接收                                // .setContentAvailable(true)                                .build())                        .build())                // Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别                .setMessage(Message.newBuilder()                        .setMsgContent(msgContent)                        .setTitle(msgTitle)                        .addExtra("message extras key", extras)                        .build())                .setOptions(Options.newBuilder()                        // 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义                        .setApnsProduction(apnsProduction)                        // 此字段是给开发者自己给推送编号,方便推送者分辨推送记录                        .setSendno(1)                        // 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天;                        .setTimeToLive(86400)                        .build())                .build();    }    /**     * 向所有平台单个或多个指定Tag用户推送消息     *     * @param tagsList     * @param notificationTitle     * @param msgTitle     * @param msgContent     * @param extras     * @return     */    private PushPayload buildPushObject_all_tagList_alertWithTitle(List tagsList, String notificationTitle, String msgTitle, String msgContent, String extras) {        //创建一个IosAlert对象,可指定APNs的alert、title等字段        //IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody("title", "alert body").build();        return PushPayload.newBuilder()                // 指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台                .setPlatform(Platform.all())                // 指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id                .setAudience(Audience.tag(tagsList))                // jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发                .setNotification(Notification.newBuilder()                        // 指定当前推送的android通知                        .addPlatformNotification(AndroidNotification.newBuilder()                                .setAlert(notificationTitle)                                .setTitle(notificationTitle)                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("androidNotification extras key", extras)                                .build())                        // 指定当前推送的iOS通知                        .addPlatformNotification(IosNotification.newBuilder()                                // 传一个IosAlert对象,指定apns title、title、subtitle等                                .setAlert(notificationTitle)                                // 直接传alert                                // 此项是指定此推送的badge自动加1                                .incrBadge(1)                                // 此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音                                .setSound("default")                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("iosNotification extras key", extras)                                // 此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification                                // 取消此注释,消息推送时ios将无法在锁屏情况接收                                // .setContentAvailable(true)                                .build())                        .build())                // Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别                .setMessage(Message.newBuilder()                        .setMsgContent(msgContent)                        .setTitle(msgTitle)                        .addExtra("message extras key", extras)                        .build())                .setOptions(Options.newBuilder()                        // 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义                        .setApnsProduction(apnsProduction)                        // 此字段是给开发者自己给推送编号,方便推送者分辨推送记录                        .setSendno(1)                        // 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天;                        .setTimeToLive(86400)                        .build())                .build();    }    /**     * 向android平台所有用户推送消息     *     * @param notificationTitle     * @param msgTitle     * @param msgContent     * @param extras     * @return     */    private PushPayload buildPushObject_android_all_alertWithTitle(String notificationTitle, String msgTitle, String msgContent, String extras) {        return PushPayload.newBuilder()                // 指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台                .setPlatform(Platform.android())                // 指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id                .setAudience(Audience.all())                // jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发                .setNotification(Notification.newBuilder()                        // 指定当前推送的android通知                        .addPlatformNotification(AndroidNotification.newBuilder()                                .setAlert(notificationTitle)                                .setTitle(notificationTitle)                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("androidNotification extras key", extras)                                .build())                        .build()                )                // Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别                .setMessage(Message.newBuilder()                        .setMsgContent(msgContent)                        .setTitle(msgTitle)                        .addExtra("message extras key", extras)                        .build())                .setOptions(Options.newBuilder()                        // 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义                        .setApnsProduction(apnsProduction)                        // 此字段是给开发者自己给推送编号,方便推送者分辨推送记录                        .setSendno(1)                        // 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒                        .setTimeToLive(86400)                        .build())                .build();    }    /**     * 向ios平台所有用户推送消息     *     * @param notificationTitle     * @param msgTitle     * @param msgContent     * @param extras     * @return     */    private PushPayload buildPushObject_ios_all_alertWithTitle(String notificationTitle, String msgTitle, String msgContent, String extras) {        return PushPayload.newBuilder()                // 指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台                .setPlatform(Platform.ios())                // 指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id                .setAudience(Audience.all())                // jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发                .setNotification(Notification.newBuilder()                        // 指定当前推送的android通知                        .addPlatformNotification(IosNotification.newBuilder()                                // 传一个IosAlert对象,指定apns title、title、subtitle等                                .setAlert(notificationTitle)                                // 直接传alert                                // 此项是指定此推送的badge自动加1                                .incrBadge(1)                                // 此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,                                // 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音                                .setSound("default")                                // 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)                                .addExtra("iosNotification extras key", extras)                                // 此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification                                // .setContentAvailable(true)                                .build())                        .build()                )                // Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别                .setMessage(Message.newBuilder()                        .setMsgContent(msgContent)                        .setTitle(msgTitle)                        .addExtra("message extras key", extras)                        .build())                .setOptions(Options.newBuilder()                        // 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义                        .setApnsProduction(apnsProduction)                        // 此字段是给开发者自己给推送编号,方便推送者分辨推送记录                        .setSendno(1)                        // 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒                        .setTimeToLive(86400)                        .build())                .build();    }    public static void main(String[] args) {//        MyJPushClient jPushUtil = new MyJPushClient();//        List aliasList = Arrays.asList("239");//        String notificationTitle = "notificationTitle";//        String msgTitle = "msgTitle";//        String msgContent = "msgContent";//        jPushUtil.sendToAliasList(aliasList, notificationTitle, msgTitle, msgContent, "exts");    }}

4.test

@RunWith(SpringRunner.class)@SpringBootTestpublic class JPushApplicationTests {    @Autowired    private MyJPushClient jPushClient;    @Test    public void testJPush() {        List aliasList = Arrays.asList("239");        String notificationTitle = "notification_title";        String msgTitle = "msg_title";        String msgContent = "msg_content";        jPushClient.sendToAliasList(aliasList, notificationTitle, msgTitle, msgContent, "exts");    }}
3e0ca34c7e58c0744a8ff885e63d636a.png

获取示例源码请转发该文章并关注Java实用技术,私信获取极光推送源码。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/538540.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

什么是ES6?

什么是ES6? ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了。Mozilla公司将在这个标准的基础上,推出JavaScript 2.0。   ECMAScript和JavaScript到底是什么关系?很多…

Babylon-AST初探-代码更新删除(Update Remove)

通过前两篇文章的介绍,大家已经了解了Create和Retrieve,我们接着介绍Update和 Remove操作。Update操作通常配合Create来完成。我们这篇文章主要介绍几个常用的NodePathAPI:replace、insert、remove。具体也可以看babel-handbook中的Manipulat…

python中时间间隔默认单位是什么_Python时间增量(以年为单位)

你需要不止一个timedelta来说明多少年过去了;你还需要知道开始(或结束)日期。(这是闰年的事。)最好的方法是使用dateutil.relativedeltaobject,但这是第三方模块。如果您想知道从某个日期起的datetime年(默认为现在),可以执行以下操作&#x…

编解码异常分析

前言 最近在做的项目,有H264解码的需求。部分H264文件解码播放后,显示为绿屏或者花屏。 分析 如何确认是否是高通硬解码的问题 adb 指令 adb root adb remount adb shell setenforce 0 adb shell setprop vendor.gralloc.disable_ubwc 1 adb shell c…

python读取数据库导出文件_python如何导出excel表格数据库数据

{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里云数据库专家保驾护航,为用户…

mysql堆溢出_为什么这个MySQL触发器会导致堆栈溢出?

我今天遇到了同样的问题,每次触发都会导致堆栈溢出.原来我的Zend社区服务器安装附带了一个默认的my.cnf文件,其中thread_stack大小设置为128K,这导致每个线程中可用于堆栈的131072字节:mysql> show variables where Variable_name thread_stack;---------------…

MySQL定义数据库对象之指定definer

mysql创建view、trigger、function、procedure、event时都会定义一个Definer: SQL SECURITY 有两个选项,一个为DEFINER,一个为INVOKER;SQL SECURITY { DEFINER | INVOKER } :指明谁有权限来执行。DEFINER 表示按定义者拥有的权限来…

js根据name获取value_js 函数的重载

js 函数的重载我们知道,很多编程语言都有函数的重载。所谓的重载,看定义:重载,简单说,就是函数或者方法有相同的名称,但是参数列表不相同的情形,这样的同名不同参数的函数或者方法之间&#xff…

python调用菜单响应事件_[Python] wxpython 编程触发菜单或按钮事件

最近逐步熟悉wxpython,编写了几个小小功能的GUI程序,GUI中免不了会有在代码中触发控件事件的业务需求。在其他Gui界面的语言中有postevent、triggerevent 调用事件名称的函数,非常方便。在wxpython里如何解决呢,上一段简单的代码。…

Angular CLI 使用教程指南参考

原文链接:http://www.cnblogs.com/bh4lm/p/6638057.html 点击阅读原文 ----------------------------------------------- Angular CLI 使用教程指南参考 Angular CLI 现在虽然可以正常使用但仍然处于测试阶段. Angular CLI 依赖 Node 4 和 NPM 3 或更高版本. 安装…

存储过程循环遍历一个月的每一天的函数_JavaScript 循环:如何处理 async/await

同步循环很久以前我写的循环是这样的:后来 JavaScript 提供了很多新的特性,现在我们会更倾向于用下面这种写法:在开发过程可能会有这么一种需求,我们需要在循环中异步处理 item,那么可以怎么做呢?异步循环如…

Angular程序架构

component,组件是Angular应用的基本构建块,你可以把一个组件理解为一段带有业务逻辑和数据的html。组件下面可以有子组件,子组件下有孙子组件,像树一样。指令:允许你向html元素添加自定义行为。模块Ngmodule&#xff1…

sqllite能连接mysql_SQLLite 可以通过SQL语言来访问的文件型SQL数据库

Web Storage分为两类:- sessionStorage:数据保存在session 对象中(临时)- localStorage:数据保存在本地硬件设备中(永久)sessionStorage:保存数据的两种方法:sessionStorage.setItem(key,val);sessionStorage.key val;读取数据的…

迭代器模式(Iterator)

迭代器模式 一. 迭代器模式 1.1 定义 提供一种方法顺序访问一个集合对象中的各种元素,而又不暴露该对象的内部表示.1.2 角色 抽象迭代器接口(Iterator).具体迭代器(ConcreteIterator).抽象聚合接口(Aggrega…

Angular启动过程介绍

1、启动时加载了哪个页面?2、启动时加载了哪些脚本?3、这些脚本做了什么事?打开Angular的命令行文件.angular-cli.json。apps节点下面。首先加载 index.html 页面。此时浏览器显示index.html的内容。再加载main.ts脚本"apps": [{..…

python解压打开文件过多_在python中使用zipfile压缩文件时层级很多,有很多层目录...

如下图本来只压缩一个文件结果这个文件所在的路径全都被压缩进去啦下面是解决方法yadirD:/databak/zipfilepathD:/zipfile.zipfilelists os.listdir(yadi)if filelists None or len(filelists) print (">>>>>>待压缩的文件目录:" ya…

易语言python1.1模块_易语言之编写模块与引入模块

本人并不精通易语言,只是对其进行一定了解后做一个简单的总结。直接新建一个易语言模块,然后添加子程序即可。子程序当然可以随意命名,实际上,易语言的子程序就和c语言的函数,java中的方法一样(实际上,java…

spring boot开发笔记——mybatis

概述 mybatis框架的优点,就不用多说了,今天这边干货主要讲mybatis的逆向工程,以及springboot的集成技巧,和分页的使用 因为在日常的开发中,当碰到特殊需求之类会手动写一下sql语句,大部分的时候完全可以用m…

Angular项目目录介绍

通过 ng new 项目名生成的项目 一级目录 Angular cli 工具生成的目录文件名不要随意修改,要不然会影响工具的使用。e2e:端到端的测试目录,用来做自动测试的。node_modules:Angular第三方包。src:应用源代码目录&#…

jvm内存模型_四种视角看JVM内存模型

1.JVM运行视角程序计数器Java虚拟机栈本地方法栈Java堆方法区1 .程序计数器程序计数器是一块较小的内存空间,它可以看作是当前线程所执行的行号指示器。这个计数器记录的是正在执行的虚拟机字节码指令的地址。此内存区域是唯一一个在JAVA虚拟机规范中没有规定任何Ou…