java高级教程 俩数之和

Test.java:

package com.itheima.ioc;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test{

    public static void main(String[] args) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

        UserDao UserDao = (UserDao) applicationContext.getBean("UserDao");

        UserDao.add();

    }

}

 

UserDao.java:

package com.itheima.ioc;

public interface UserDao {

    public void add();

}

 

UserDaoimp.java:

package com.itheima.ioc;

 

public class UserDaoimp implements UserDao {

    public void add(){

       int x = 13;

       int y = 14;

       int sum;

       sum = x+y;

       System.out.println("x的值为:"+x);

       System.out.println("y的值为:"+y);

       System.out.println("x与y的和是:"+sum);

    }

   

 

}

 

Xml文件:

"http://www.springframework.org/schema/beans"

    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-4.3.xsd">

   

    "UserDao" class="com.itheima.ioc.UserDaoimp"/>  

 java高级教程 俩数之和_第1张图片

 

你可能感兴趣的:(java高级教程 俩数之和)