java-spring-aop

 OrderDao:

package com.ssm.aop.dao;

import com.ssm.aop.domain.Order;

public interface OrderDao {

	public void saveOrder(Order order);

	public void savePayInfo(Order order);

}

OrderDaoImpl:

package com.ssm.aop.dao.impl;

import com.ssm.aop.dao.OrderDao;
import com.ssm.aop.domain.Order;


public class OrderDaoImpl implements OrderDao{
	
    @Override
    public void saveOrder(Order order){
    	System.out.println("保存订单信息:" +order);
    }
    
    @Override
    public void savePayInfo(Order order){
    	System.out.println("保存支付信息:" +order);
    }
}

Order:

package com.ssm.aop.domain;

public class Order {
	private String goodsName;
	private float money;
	private int count;
	public String getGoodsName() {
		return goodsName;
	}
	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}
	public float getMoney() {
		return money;
	}
	public void setMoney(float money) {
		this.money = money;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	@Override
	public String toString() {
		return "Order [goodsName=" + goodsName + ", money=" + money + ", count=" + count + "]";
	}
	
	public Order(String goodsName, float money,int count){
		super();
		this.goodsName=goodsName;
		this.money=money;
		this.count=count;
	}
}

OrderService:

package com.ssm.aop.service;

import com.ssm.aop.domain.Order;

public interface OrderService {

	public void submitOrder(Order order);

	public void payOrder(Order order);

}

OrderServiceImpl:

package com.ssm.aop.service.impl;

import com.ssm.aop.dao.OrderDao;
import com.ssm.aop.domain.Order;
import com.ssm.aop.service.OrderService;

public class OrderServiceImpl implements OrderService{
	private OrderDao orderDao;
	public void setOrderDao(OrderDao orderDao){
		this.orderDao=orderDao;
	}
    
	@Override
	public void submitOrder(Order order){
		System.out.println("提交订单..");
		orderDao.saveOrder(order);
	}
	
	@Override
	public void payOrder(Order order){
		System.out.println("支付订单..");
		orderDao.savePayInfo(order);
	}
}

TestAOP:

package com.ssm.aop.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ssm.aop.domain.Order;
import com.ssm.aop.service.OrderService;

public class TestAOP {
    
	@Test
	public void orderServiceTest() {
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationcontext.xml");
		OrderService service = ctx.getBean("orderService",OrderService.class);
		
		Order order =new Order("iphone 30", 10000, 1);
		service.submitOrder(order);
	}
}

applicationContext:

<?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: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/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
     
     <bean id="orderDao" class="com.ssm.aop.dao.impl.OrderDaoImpl">
   
   </bean>
        
   <bean id="orderService" class="com.ssm.aop.service.impl.OrderServiceImpl">
   <property name="orderDao" ref="orderDao"></property>
   </bean>
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值