zoukankan      html  css  js  c++  java
  • proxy Static方式

    package com.xk.spring.kp04_aop.proxy.s1_static;
    
    public interface IStudentService {
        public void save(Student stu);
    }
    package com.xk.spring.kp04_aop.proxy.s1_static;
    
    public class ImplStudentService implements IStudentService {
        @Override
        public void save(Student stu) {
            // dao实现方法
            System.out.println("保存...");
        }
    }

      

    package com.xk.spring.kp04_aop.proxy.s1_static;
    
    public class StudentServiceProoxy implements IStudentService {
        
        private ImplStudentService service;
    
        public StudentServiceProoxy(ImplStudentService service) {
            this.service = service;
        }
    
        @Override
        public void save(Student stu) {
            System.out.println("beginTranstation()");
            service.save(stu);
            System.out.println("commit()");
    
        }
    
    }
    package com.xk.spring.kp04_aop.proxy.s1_static;
    
    public class Student {
        private String name;
        private Integer age;
    
        public Student() {
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        public Student(String name, Integer age) {
            this.name = name;
            this.age = age;
        }
    
        @Override
        public String toString() {
            return "Student [name=" + name + ", age=" + age + "]";
        }
        
    }
    package com.xk.spring.kp04_aop.proxy.s1_static;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class StaticProxyTest {
        @Autowired
        @Qualifier("ProxyService")
        private IStudentService transeriver;
        
        @Test
        public void TestStaticProxy() throws Exception {
            transeriver.save(new Student("张三", 18));
        }
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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">
        <!-- id唯一标识
                自动创建类的对象
         -->
        <bean id="StudentService"
            class="com.xk.spring.kp04_aop.proxy.s1_static.ImplStudentService" />
        <bean id="ProxyService"
            class="com.xk.spring.kp04_aop.proxy.s1_static.StudentServiceProoxy">
            <constructor-arg name="service" ref="StudentService"/>
        </bean>
    </beans>
  • 相关阅读:
    送给每天用电脑超4小时的朋友!!
    股票技术指标分析详细
    2003安装新版MSN9的方法 / MSN9 for 2003
    买卖股票基本原则新手参考
    更改Windows软件默认安装路径
    永不套牢的方法(教你正确止损)
    股票的技术参数很多,图线参数常见的有这些
    教育网ftp大全
    【笔记】【汇编语言】第4章 第一个程序
    【笔记】【汇编语言】第2章 寄存器
  • 原文地址:https://www.cnblogs.com/huike/p/6637027.html
Copyright © 2011-2022 走看看