Java八種常見的設計模式

一、單例模式

????????單例模式是(Singleton Pattern)Java中最常用的設計模式之一,它保證一個類僅有一個實例,并提供一個全局訪問點。

????????實現單例模式的核心是將類的構造方法私有化,以防止外部直接通過構造函數創建實例。同時,類內部需要提供一個靜態方法或變量來獲取該類的唯一實例。單例模式分為餓漢式單例(立即加載)和懶漢式單例(延遲加載)。

餓漢式單例:線程安全

public class Singleton1 {/*** 在類的內部可以訪問私有結構,所以可以在類的內部產生實例化對象*/private static Singleton1 instance = new Singleton1();/*** private 聲明構造*/private Singleton1() {}/*** 返回對象實例*/public static Singleton1 getInstance() {return instance;}
}

懶漢式單例:?

????????當多個線程并發執行 getInstance 方法時,懶漢式會存在線程安全問題,所以用到了 synchronized 來實現線程的同步,當一個線程獲得鎖的時候其他線程就只能在外等待其執行完畢。而餓漢式則不存在線程安全的問題。

public class Singleton2 {/*線程不安全*/
//    // 指向自己實例的私有靜態引用
//    private static Singleton2 singleton2;
//
//    // 私有的構造方法
//    private Singleton2(){}
//
//    // 以自己實例為返回值的靜態的公有方法,靜態工廠方法
//    public static Singleton2 getSingleton2(){
//        // 被動創建,在真正需要使用時才去創建
//        if (singleton2 == null) {
//            singleton2 = new Singleton2();
//        }
//        return singleton2;
//    }/*** 聲明變量*/private static volatile Singleton2 singleton = null;/*** 私有構造方法*/private Singleton2() {}/*** 提供對外方法* @return*/public static Singleton2 getInstance() {// 還未實例化if (singleton == null) {synchronized (Singleton2.class) {if (singleton == null) {singleton = new Singleton2();}}}return singleton;}
}

JDK 中的應用:

  • java.lang.Runtime.getRuntime()
  • java.util.logging.Logger

Spring 中的應用:Spring 的 Bean 默認是單例模式。可以通過 @Scope("prototype") 將其改為多例。

二、工廠模式

根據需求,在用于不同的場景下,創建不同的對象。

public interface Sender {void Send();
}public class MailSender implements Sender{@Overridepublic void Send() {System.out.println("This is mail sender...");}
}public class SmsSender implements Sender{@Overridepublic void Send() {System.out.println("This is sms sender...");}
}public class FactoryPattern {public static void main(String[] args) {Sender sender = produce("mail");sender.Send();}public static Sender produce(String str) {if ("mail".equals(str)) {return new MailSender();} else if ("sms".equals(str)) {return new SmsSender();} else {System.out.println("輸入錯誤...");return null;}}
}

????????在此基礎上,若存在多個分支判斷條件,很容易出現傳遞的字符串出錯,則不能正確創建對象,因此可以多封裝一個類,用來將分支判斷替換為每個方法,降低耦合,這種模式是多個工廠方法模式,是提供多個工廠方法,分別創建對象。?

public interface Sender {void Send();
}public class MailSender implements Sender{@Overridepublic void Send() {System.out.println("This is mail sender...");}
}public class SmsSender implements Sender{@Overridepublic void Send() {System.out.println("This is sms sender...");}
}public class SendFactory {public Sender produceMail() {return new MailSender();}public Sender produceSms() {return new SmsSender();}
}public class FactoryPattern {public static void main(String[] args) {SendFactory factory = new SendFactory();Sender sender = factory.produceMail();sender.Send();}
}

JDK 中的應用:

  • java.util.Calendar.getInstance()
  • javax.xml.parsers.DocumentBuilderFactory.newInstance()

Spring 中的應用:

  • BeanFactory 和 ApplicationContext 都是工廠模式的體現。

?三、建造者模式

????????建造者模式用于創建復雜對象,就是將復雜對象的創建過程拆分成多個簡單對象的創建過程,并將這些簡單對象組合起來構建出復雜對象。

角色組成:

  1. 產品類(Product):表示被創建的復雜對象。它通常包含多個部分或者組成,并由具體的建造者逐步構建而成。?Meal
  2. 抽象建造者類(Builder):定義了建造復雜對象所需要的各個部分的創建方法。它通常包括多個構建方法和一個返回產品的方法。?MealBuilder
  3. 具體建造者類(ConcreteBuilder):實現Builder接口,并提供各個部分或者組成的構建方法。?BeefBurgerMealBuilder、ChickenMealBuilder、ShrimpMealBuilder
  4. 指揮者類(Director):負責控制建造者的構建順序,指揮建造者如何構建復雜對象。MealDirector
/*** @Author: EstellaQ* @Date: 2025/4/17 15:43* @Description: 產品類**/
@Data
public class Meal {//漢堡包private String burger;//薯條private String fries;//飲料private String drink;}/*** @Author: EstellaQ* @Date: 2025/4/17 15:44* @Description: 建造者接口**/
public interface MealBuilder {Meal meal=new Meal();//構建漢堡public void buildBurger();//構建薯條public void buildFries();//構建飲料public void buildDrink();public default Meal getMeal(){return meal;}
}/*** @Author: EstellaQ* @Date: 2025/4/17 15:46* @Description:  牛肉套餐建造者**/
public class BeefBurgerMealBuilder implements MealBuilder{@Overridepublic void buildBurger() {meal.setBurger("牛肉漢堡");}@Overridepublic void buildFries() {meal.setFries("大份薯條");}@Overridepublic void buildDrink() {meal.setDrink("中杯可樂");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 15:46* @Description: 雞肉套餐建造者**/
public class ChickenMealBuilder implements MealBuilder{@Overridepublic void buildBurger() {meal.setBurger("雞肉漢堡");}@Overridepublic void buildFries() {meal.setFries("中份薯條");}@Overridepublic void buildDrink() {meal.setDrink("大杯果汁");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 15:46* @Description: 蝦肉套餐建造者**/
public class ShrimpMealBuilder implements MealBuilder{@Overridepublic void buildBurger() {meal.setBurger("蝦肉漢堡");}@Overridepublic void buildFries() {meal.setFries("小份薯條");}@Overridepublic void buildDrink() {meal.setDrink("大杯芬達");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 15:50* @Description: 指揮者**/
public class MealDirector {private MealBuilder mealBuilder;public void setMealBuilder(MealBuilder mealBuilder){this.mealBuilder=mealBuilder;}public Meal getMeal(){return mealBuilder.getMeal();}//制作套餐public void constructMeal(){mealBuilder.buildBurger();mealBuilder.buildFries();mealBuilder.buildDrink();}
}public class BuilderPattern {public static void main(String[] args) {//創建指導者MealDirector director=new MealDirector();//執導建造牛肉套餐director.setMealBuilder(new BeefBurgerMealBuilder());director.constructMeal();Meal meal = director.getMeal();System.out.println("牛肉套餐:"+meal.toString());//雞肉套餐director.setMealBuilder(new ChickenMealBuilder());director.constructMeal();Meal meal2 = director.getMeal();System.out.println("雞肉套餐:"+meal2.toString());//蝦肉套餐director.setMealBuilder(new ShrimpMealBuilder());director.constructMeal();Meal meal3 = director.getMeal();System.out.println("蝦肉套餐:"+meal3.toString());}
}

JDK 中的應用:

  • StringBuilder
  • Stream.Builder

Spring 中的應用:

  • UriComponentsBuilder 用于構建 URI。

?四、?適配器模式

????????它允許將不兼容的對象轉換成可兼容的接口。主要目的是解決在不改變現有代碼的情況下,使不兼容的接口之間能夠正常工作,通過創建一個中間轉換的適配器來將一個對象轉換成我們所需要的接口。

角色組成

  • 目標接口(target):需要適配的標準接口。
  • 源對象(source):需要被適配的不兼容對象。
  • 適配器對象(adapter):充當中間轉換角色,該對象將源對象轉換成目標接口。
/*** @Author: EstellaQ* @Date: 2025/4/17 16:20* @Description: 目標接口**/
public interface Target {/*** 翻譯* @param source 母語* @param target 要翻譯成的語種* @param words 內容*/void translate(String source,String target,String words);
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:20* @Description: 源對象**/
public class Translator {//英——》漢public void translateInZh(String words){if("hello world!".equals(words)){System.out.println("翻譯成中文:”你好世界!“");}}//漢——》英public void translateInEn(String words){if("你好世界!".equals(words)){System.out.println("Translate in English:”hello world!“");}}
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:21* @Description: 類適配器:通過多重繼承目標接口和被適配者類方式來實現適配**/
public class ClassAdapter extends Translator implements Target{@Overridepublic void translate(String source, String target, String words) {if("中文".equals(source) && "英文".equals(target)) {//漢--》英this.translateInEn(words);} else {//英--》漢this.translateInZh(words);}}
}public class AdapterPattern {public static void main(String[] args) {//創建一個類適配器對象ClassAdapter adapter=new ClassAdapter();adapter.translate("中文", "英文", "你好世界!");adapter.translate("英語","中文","hello world!");}
}

?五、?裝飾器模式

裝飾器模式在不改變原始類的基礎上,動態累積擴展其功能。原始對象和裝飾類對象都要實現原始對象的接口。

/*** @Author: EstellaQ* @Date: 2025/4/17 16:55* @Description: 原始對象的接口**/
public interface ICoffee {void makeCoffee();
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:56* @Description: 原始對象**/
public class OriginalCoffee implements ICoffee{@Overridepublic void makeCoffee() {System.out.print("原味咖啡 ");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:56* @Description: 裝飾器基類**/
public abstract class CoffeeDecorator implements  ICoffee{private  ICoffee coffee;public CoffeeDecorator(ICoffee coffee){this.coffee=coffee;}@Overridepublic void makeCoffee() {coffee.makeCoffee();}
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:58* @Description: 加奶的裝飾**/
public class MilkDecorator extends CoffeeDecorator{public MilkDecorator(ICoffee coffee) {super(coffee);}@Overridepublic void makeCoffee() {super.makeCoffee();addMilk();}private void addMilk(){System.out.print("加奶 ");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 16:58* @Description: 加糖的裝飾**/
public class SugarDecorator extends CoffeeDecorator{public SugarDecorator(ICoffee coffee) {super(coffee);}@Overridepublic void makeCoffee() {super.makeCoffee();addSugar();}private void addSugar(){System.out.print("加糖 ");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 17:00* @Description: 裝飾器模式測試**/
public class DecoratorPattern {public static void main(String[] args) {//原味咖啡ICoffee coffee=new OriginalCoffee();coffee.makeCoffee();System.out.println("");//加奶的咖啡coffee=new MilkDecorator(coffee);coffee.makeCoffee();System.out.println("");//先加奶后加糖的咖啡coffee=new SugarDecorator(coffee);coffee.makeCoffee();}
}

JDK 中的應用:

  • java.io.BufferedInputStream 和 java.io.BufferedOutputStream

Spring 中的應用:

  • BeanPostProcessor 用于動態修改 Bean 的行為。

六、?代理模式

????????代理模式的結構比較簡單,主要是通過定義一個繼承抽象主題的代理來包含真實主題,從而實現對真實主題的訪問,下面來分析其基本結構。

角色組成:

  • 抽象主題(Subject)類(業務接口類):通過接口或抽象類聲明真實主題和代理對象實現的業務方法,服務端需要實現該方法。
  • 真實主題(Real Subject)類(業務實現類):實現了抽象主題中的具體業務,是代理對象所代表的真實對象,是最終要引用的對象。
  • 代理(Proxy)類:提供了與真實主題相同的接口,其內部含有對真實主題的引用,它可以訪問、控制或擴展真實主題的功能。

靜態代理?

????????靜態代理服務于單個接口,我們來考慮實際工程中的一個例子,現在已經有業務代碼實現一個增刪功能,原有的業務代碼由于仍有大量程序無法改變,現在新增需求,即以后每執行一個方法輸出一個日志。

/*** @Author: EstellaQ* @Date: 2025/4/17 17:38* @Description: 業務接口**/
public interface DateService {void add();void del();
}/*** @Author: EstellaQ* @Date: 2025/4/17 17:39* @Description: 委托類**/
public class DateServiceImplA implements DateService{@Overridepublic void add() {System.out.println("成功添加!");}@Overridepublic void del() {System.out.println("成功刪除!");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 17:40* @Description: 代理類**/
public class DateServiceProxy implements DateService{DateServiceImplA server = new DateServiceImplA();@Overridepublic void add() {server.add();System.out.println("程序執行add方法,記錄日志.");}@Overridepublic void del() {server.del();System.out.println("程序執行del方法,記錄日志.");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 17:39* @Description: 代理模式測試**/
public class ProxyPattern {public static void main(String[] args) {DateService service = new DateServiceProxy();service.add();service.del();}
}

動態代理?

????????動態代理可以幫助我們僅僅在需要的時候再創建代理類,減少資源浪費,此外由于動態代理是一個模板的形式,也可以減少程序的代碼量,例如在靜態代碼示例中,我們在每個方法中加入System.out.println("程序執行***方法,記錄日志.");,當業務方法非常多時,我們也得為每個業務方法加上記錄日志的語句,而動態代理中將方法統一管理,無論幾個業務方法都只需要一條記錄語句即可實現,具體請看代碼。

/*** @Author: EstellaQ* @Date: 2025/4/17 17:48* @Description: 動態代理的代理類**/
public class ProxyInvocationHandler implements InvocationHandler {private DateService service;public ProxyInvocationHandler(DateService service) {this.service = service;}public Object getDateServiceProxy() {return Proxy.newProxyInstance(this.getClass().getClassLoader(), service.getClass().getInterfaces(), this);}@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {var result = method.invoke(service, args); // 讓service調用方法,方法返回值System.out.println(proxy.getClass().getName() + "代理類執行" + method.getName() + "方法,返回" + result +  ",記錄日志!");return result;}
}/*** @Author: EstellaQ* @Date: 2025/4/17 17:39* @Description: 代理模式測試**/
public class ProxyPattern {public static void main(String[] args) {
//靜態代理
//        DateService service = new DateServiceProxy();
//        service.add();
//        service.del();
//動態代理DateService serviceA = new DateServiceImplA();DateService serviceProxy = (DateService) new ProxyInvocationHandler(serviceA).getDateServiceProxy();serviceProxy.add();serviceProxy.del();}
}

七、?策略模式

????????該模式定義了一系列算法,并將每個算法封裝起來,使它們可以相互替換,且算法的變化不會影響使用算法的客戶。策略模式屬于對象行為模式,它通過對算法進行封裝,把使用算法的責任和算法的實現分割開來,并委派給不同的對象對這些算法進行管理。? 我認為跟工廠模式的思想很相似? ??

角色組成:??

抽象策略(Strategy)類
具體策略(Concrete Strategy)類
環境(Context)類

/*** @Author: EstellaQ* @Date: 2025/4/17 18:04* @Description: 抽象算法的策略類,定義所有支持的算法的公共接口**/
public interface Strategy {/*** 算法方法*/public void AlgorithmInterface();
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:04* @Description: 策略實現類A**/
public class ConcreteStrategyA implements Strategy{@Overridepublic void AlgorithmInterface() {System.out.println("算法A的實現");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:04* @Description: 策略實現類B**/
public class ConcreteStrategyB implements Strategy{@Overridepublic void AlgorithmInterface() {System.out.println("算法B的實現");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:04* @Description: 策略實現類C**/
public class ConcreteStrategyC implements Strategy{@Overridepublic void AlgorithmInterface() {System.out.println("算法C的實現");}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:06* @Description: 上下文,維護一個對策略類對象的引用**/
public class Context {private Strategy strategy;public Context(Strategy strategy) {this.strategy = strategy;}public void contextInterface(){strategy.AlgorithmInterface();}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:03* @Description: 策略模式的測試類**/
public class StrategyPattern {public static void main(String[] args) {Context context;context = new Context(new ConcreteStrategyA());context.contextInterface();context = new Context(new ConcreteStrategyB());context.contextInterface();context = new Context(new ConcreteStrategyC());context.contextInterface();}
}

JDK 中的應用:

  • java.util.Comparator 是典型的策略模式。

Spring 中的應用:

  • 事務管理(TransactionManager),支持編程式和聲明式事務。

八、?觀察者模式

????????觀察者模式是一種行為型設計模式,它定義了一種一對多的依賴關系,當一個對象的狀態發生改變時,其所有依賴者都會收到通知并自動更新。

角色組成:

  • 主題(Subject):也稱為被觀察者或可觀察者,它是具有狀態的對象,并維護著一個觀察者列表。主題提供了添加、刪除和通知觀察者的方法。
  • 觀察者(Observer):觀察者是接收主題通知的對象。觀察者需要實現一個更新方法,當收到主題的通知時,調用該方法進行更新操作。
  • 具體主題(Concrete Subject):具體主題是主題的具體實現類。它維護著觀察者列表,并在狀態發生改變時通知觀察者。
  • 具體觀察者(Concrete Observer):具體觀察者是觀察者的具體實現類。它實現了更新方法,定義了在收到主題通知時需要執行的具體操作。
/*** @Author: EstellaQ* @Date: 2025/4/17 18:42* @Description: 主題類,被觀察者**/
public class Subject {private List<Observer> observers = new ArrayList<Observer>();private int state;public int getState() {return state;}public void setState(int state) {this.state = state;notifyAllObservers();}public void attach(Observer observer){observers.add(observer);}public void notifyAllObservers(){for (Observer observer : observers) {observer.update();}}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:43* @Description: 被通知者的抽象類**/
public abstract class Observer {protected Subject subject;public abstract void update();}/*** @Author: EstellaQ* @Date: 2025/4/17 18:46* @Description: 被通知者的實現類**/
public class BinaryObserver extends Observer{public BinaryObserver(Subject subject){this.subject = subject;this.subject.attach(this);}@Overridepublic void update() {System.out.println( "Binary String: "+ Integer.toBinaryString( subject.getState() ) );}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:46* @Description: 被通知者的實現類**/
public class OctalObserver extends Observer{public OctalObserver(Subject subject){this.subject = subject;this.subject.attach(this);}@Overridepublic void update() {System.out.println( "Octal String: "+ Integer.toOctalString( subject.getState() ) );}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:46* @Description: 被通知者的實現類**/
public class HexaObserver extends Observer{public HexaObserver(Subject subject){this.subject = subject;this.subject.attach(this);}@Overridepublic void update() {System.out.println( "Hex String: "+ Integer.toHexString( subject.getState() ) );}
}/*** @Author: EstellaQ* @Date: 2025/4/17 18:48* @Description: 觀察者模式測試**/
public class ObserverPattern {public static void main(String[] args) {Subject subject = new Subject();new HexaObserver(subject);new OctalObserver(subject);new BinaryObserver(subject);System.out.println("First state change: 15");subject.setState(15);System.out.println("Second state change: 10");subject.setState(10);}
}

JDK 中的應用:

  • java.util.Observer 和 java.util.Observable
  • javax.swing.event.ChangeListener

Spring 中的應用:

  • ApplicationEvent 和 ApplicationListener 是典型實現。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/77284.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/77284.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/77284.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

4.17---實現商鋪和緩存與數據庫雙寫一致以及宕機處理

實現商鋪和緩存與數據庫雙寫一致&#xff08;以及強雙寫一致策略&#xff09; redis點評項目采用的是延時雙刪策略 雙刪&#xff1a; 我們更新完數據庫之后刪除緩存&#xff0c;這樣即使有線程并發進來查詢&#xff0c;會發現緩存中沒有數據&#xff0c;從而會去mysql中查找…

滑動窗口209. 長度最小的子數組

1.題目 給定一個含有 n 個正整數的數組和一個正整數 target 。 找出該數組中滿足其總和大于等于 target 的長度最小的 子數組 [numsl, numsl1, ..., numsr-1, numsr] &#xff0c;并返回其長度。如果不存在符合條件的子數組&#xff0c;返回 0 。 示例 1&#xff1a; 輸入&…

osu ai 論文筆記 DQN

e https://theses.liacs.nl/pdf/2019-2020-SteeJvander.pdf Creating an AI for the Rhytm Game osu! 20年的論文 用監督學習訓練移動模型100首歌能達到95準確率 點擊模型用DQN兩千首歌65準確率 V抖用的居然不是強化學習&#xff1f; 5,6星打96準確度還是有的東西的 這是5.…

如何通過工具實現流程自動化

通過自動化工具&#xff0c;企業可以顯著提高工作效率、降低人為錯誤、節省時間和成本。現代企業的運營中&#xff0c;流程管理是確保工作順暢的關鍵&#xff0c;而人工處理繁瑣的流程不僅容易出錯&#xff0c;還會消耗大量的時間和人力資源。通過使用適合的自動化工具&#xf…

mongodb 4.0+多文檔事務的實現原理

1. 副本集事務實現&#xff08;4.0&#xff09;? ?非嚴格依賴二階段提交? MongoDB 4.0 在副本集環境中通過 ?全局邏輯時鐘&#xff08;Logical Clock&#xff09;? 和 ?快照隔離&#xff08;Snapshot Isolation&#xff09;? 實現多文檔事務&#xff0c;事務提交時通過…

《理解 Java 泛型中的通配符:extends 與 super 的使用場景》

大家好呀&#xff01;&#x1f44b; 今天我們要聊一個讓很多Java初學者頭疼的話題——泛型通配符。別擔心&#xff0c;我會用最通俗易懂的方式&#xff0c;帶你徹底搞懂這個看似復雜的概念。準備好了嗎&#xff1f;Let’s go! &#x1f680; 一、為什么我們需要泛型通配符&…

速盾:高防CDN訪問多了會影響源站嗎?

在當今數字化時代&#xff0c;內容分發網絡&#xff08;CDN&#xff09;已經成為保障網站性能和用戶體驗的重要工具。特別是高防CDN&#xff0c;它不僅能夠加速內容傳輸&#xff0c;還能有效抵御各種類型的網絡攻擊&#xff0c;確保業務的連續性和穩定性。然而&#xff0c;一些…

Unity URP Moblie AR示例工程,真機打包出來,沒陰影

效果&#xff1a; unity ar示例演示 現象&#xff1a; 真機打包測試私活沒有陰影 Unity版本&#xff1a;2022.3.4f1c1 分析原因&#xff1a; Prefab &#xff1a;ARFeatheredPlane中也有材質&#xff0c;一個用于環境遮擋&#xff0c;一個用于陰影接受。 按理說有啊。 urp …

win10下github libiec61850庫編譯調試sntp_example

libiec61850 https://github.com/mz-automation/libiec61850 v1.6 簡介 libiec61850 是一個開源&#xff08;GPLv3&#xff09;的 IEC 61850 客戶端和服務器庫實現&#xff0c;支持 MMS、GOOSE 和 SV 協議。它使用 C 語言&#xff08;根據 C99 標準&#xff09;實現&#xf…

Microsoft SQL Server Management 一鍵刪除數據庫所有外鍵

DECLARE ESQL VARCHAR(1000); DECLARE FCursor CURSOR --定義游標 FOR (SELECT ALTER TABLE O.name DROP CONSTRAINT F.name; AS CommandSQL from SYS.FOREIGN_KEYS F JOIN SYS.ALL_OBJECTS O ON F.PARENT_OBJECT_ID O.OBJECT_ID WHERE O.TYPE U AND F.TYPE …

新型多機器人協作運輸系統,輕松應對復雜路面

受到魚類、鳥類和螞蟻等微小生物體協作操縱的啟發&#xff0c;研究人員開發了多機器人協作運輸系統&#xff08;Multirobot Cooperative Transportation Systems&#xff0c;MRCTS&#xff09;運輸單個機器人無法處理的重型超大物體&#xff0c;可用于搜救行動、災難響應、軍事…

Framework Binder架構分解

整個 Binder 架構所涉及的總共有以下 5 個目錄&#xff1a; 1. /framework/base/core/java/(Java) 2. /framework/base/core/jni/ (JNI) 3&#xff0c;/framework/native/libs/binder (Native) 4&#xff0c;/framework/native/cmds/servicemanager/ (Native) 5&#xff0c…

騰訊云對象存儲以及項目業務頭像上傳

騰訊云上傳步驟&#xff1a; service-vod模塊化中 ①、參考文檔&#xff0c;引入依賴 ②、配置文件application.properties ③、創建工具類 初始化bean的時候讀取配置文件 Component public class ConstantPropertiesUtil implements InitializingBean{Value("${t…

LeetCode hot 100—括號生成

題目 數字 n 代表生成括號的對數&#xff0c;請你設計一個函數&#xff0c;用于能夠生成所有可能的并且 有效的 括號組合。 示例 示例 1&#xff1a; 輸入&#xff1a;n 3 輸出&#xff1a;["((()))","(()())","(())()","()(())",&…

SpringBoot企業級開發之【文章分類-新增文章分類】

看一下新增文章的需求&#xff1a; 接口文檔&#xff1a; 開發思路&#xff1a; 先在controller下去創建add方法&#xff0c;方法內導入Service類獲取add的結果&#xff1b;再在Service接口下去創建add的方法&#xff1b;然后在Service實現類下去實現方法的作用&#xff0c;且導…

Minecraft盔甲機制詳解(1.9之后)

Minecraft的盔甲有很多種&#xff0c;但是評判盔甲的好壞&#xff0c;通常玩家會使用一個變量來評判——護甲值 護甲值的機制很簡單&#xff0c;一格護甲值 &#xff08;半個灰色的衣服圖標&#xff09;最多能提供4%的防御 護甲值在不開作弊的生存模式理論上限是20點&#xf…

為什么要給單片機植入操作系統

給單片機植入操作系統&#xff08;通常是實時操作系統&#xff0c;RTOS&#xff09;主要是為了在資源有限的環境中實現更高效、更可靠的多任務管理和系統調度。以下是主要原因和優勢&#xff1a; 1. 多任務并行處理 背景&#xff1a;單片機通常需要同時處理多個任務&#xff0…

Arduino+ESP826601s模塊連接阿里云并實現溫濕度數據上報

ArduinoESP826601s模塊連接阿里云并實現溫濕度數據上報 一、前言二、準備工作三、程序代碼1. Arduino的程序2. ESP826601的程序3. 上面程序需要注意的地方 四、運行結果五、結束語 一、前言 看完我這三篇文章&#xff0c;相信各位朋友對于阿里云物聯網平臺的使用都有了一定的認…

Java 工廠設計模式詳解:用統一入口打造靈活可擴展的登錄系統----掌握 Spring 源碼的基礎第一步

一、前言 在實際開發中&#xff0c;我們經常面臨以下場景&#xff1a; 系統支持多種登錄方式&#xff08;用戶名密碼、管理員登錄、OAuth 登錄、短信登錄等&#xff09; 每種登錄方式的認證邏輯不同 我們希望對外提供一個統一的接口調用&#xff0c;而不暴露具體實現 這個…

Windows Acrobat Pro DC-v2025.001.20435-x64-CN-Portable便攜版

Windows Acrobat Pro 鏈接&#xff1a;https://pan.xunlei.com/s/VOO1nMjQ1Qf53dyISGne0c_9A1?pwdsfgn# Acrobat Pro 2024 專業增強版特色 ● 創建和編輯 PDF 文件&#xff1a;可以將各種類型的文檔轉換為 PDF 格式&#xff0c;并進行編輯和修改。 ● 合并和拆分 PDF&#…