![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6209687bc61734f275ac57c8d7e00638.png)
public class test01 {
public static void main(String[] args) {
ApplicationContext applicationContext=new AnnotationConfigApplicationContext(SystemConfigration.class);
OrderController orderController = (OrderController) applicationContext.getBean("orderController");
int arr[]={1,2};
orderController.submitOrder(arr);
}
}
@Configuration
@ComponentScan(basePackages = "cn.goktech")
public class SystemConfigration {
}
@Controller("orderController")
public class OrderController {
@Autowired
IOrderService iOrderService;
public void submitOrder(int[] cartIdArr) {
System.out.println("控制层,调用service");
iOrderService.submitOrder(cartIdArr);
}
}
public interface IOrderService {
public void submitOrder(int[] cartIdArr);
}
@Service("iOrderService")
public class OrderServiceImp implements IOrderService {
@Autowired
ICartDao iCartDao;
@Autowired
IOrderDao iOrderDao;
@Autowired
IOrderDetailDao iOrderDetailDao;
@Override
public void submitOrder(int[] cartIdArr) {
System.out.println("订单提交service调用到了");
iOrderDao.insert("订单新增一条");
for (int cartId : cartIdArr
) {
iOrderDetailDao.insert("新增详细详细一条");
}
iCartDao.delete(cartIdArr);
}
}
public interface IOrderDao {
public void insert(Object object);
}
@Repository("iOrderDao")
public class OrderDaoImp implements IOrderDao {
@Override
public void insert(Object object) {
System.out.println("insert into order....");
}
}
========================================================================
public interface IOrderDetailDao {
public void insert(Object object);
}
@Repository("iOrderDetailDao")
public class OrderDetailDaoImp implements IOrderDetailDao {
@Override
public void insert(Object object) {
System.out.println("insert into order_detail");
}
}
=======================================================================
public interface ICartDao {
public void delete(int[] cartIdArr);
}
@Repository("iCartDao")
public class CartDaoImp implements ICartDao {
@Override
public void delete(int[] cartIdArr) {
System.out.println("delete from cart where id in()"+cartIdArr);
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3c83d8a050efb8c6f5aac4a16d123f45.png)