極光推送指定用戶推送_干貨|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.pswp.cn/news/538540.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/538540.shtml
英文地址,請注明出處:http://en.pswp.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…