zoukankan      html  css  js  c++  java
  • 23种设计模式之门面模式

    //这是基于xml把对象放入容器中的操作
    <?
    xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="bs" class="com.dz147.Validator.BookServiceImpl"/> <bean id="bs2" class="com.dz147.Validator.BookServiceImpl2"/> </beans>
    package com.dz147.Validator;
    
    public interface BookService {
        public void getInfo();
    }
    
    //实现
    public class BookServiceImpl implements BookService {
        @Override
        public void getInfo() {
            System.out.println("这是第一个实现");
        }
    }

    使用

    public class TestSpring {
        public static void main(String[] args) {
            ClassPathXmlApplicationContext cc =
                    new ClassPathXmlApplicationContext("spring/testSpring.xml");
            Object bs = cc.getBean("bs2");
            ((BookService)bs).getInfo();
        }
    }

    以上是基于XML

    使用java注解

    //使用java注解把对象放入Ioc容器中

    @Configuration
    public class BookServiceJavaStyle {
    
        @Bean
        public BookService xxx(){
            return new BookServiceImpl2();
        }
    }
    public class BookServiceImpl2 implements BookService {
        @Override
        public void getInfo() {
            System.out.println("这是第二个实现");
        }
    }
    public class TestSpring {
        public static void main(String[] args) {
            /*ClassPathXmlApplicationContext cc =
                    new ClassPathXmlApplicationContext("spring/testSpring.xml");
            Object bs = cc.getBean("bs2");
            ((BookService)bs).getInfo();*/
            //java注解方式
            newJavaStyle();
        }
    
        public static void newJavaStyle() {
            AnnotationConfigApplicationContext acc =
                    new AnnotationConfigApplicationContext(BookServiceJavaStyle.class);
            acc.getBean(BookService.class).getInfo();
        }
    }
  • 相关阅读:
    上班5个月总结
    使用余弦定理计算两篇文章的相似性
    9月10日 小结
    软件测试
    《增长黑客》笔记
    统计学术语
    数据分析师:数据分析工作常见七种错误及其规避技巧(转自经管之家)
    输入一个日期,计算这个日期与 2018-03-12差多少天;
    求输入数字的阶乘 及加和 #s=1!+2!+3!+…..+n!
    列表去重
  • 原文地址:https://www.cnblogs.com/dzcici/p/10112910.html
Copyright © 2011-2022 走看看