• java高级教程 圆 圆柱 面积


    Test:

    package com.m.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.say(3,3.14);

           userDao.say(5,3.14);

        }

     

    }

     

    Test01:

    package com.m.ioc;

    import org.springframework.context.ApplicationContext;

    import

       org.springframework.context.support.ClassPathXmlApplicationContext;

    public class Test01 {

        public static void main(String[] args){

           ApplicationContext applicationContext =

                  new ClassPathXmlApplicationContext("applicationContext.xml");

           UserService userService =

                  (UserService) applicationContext.getBean("userService");

           userService.say(4,18.84);

        }

     

    }

     

    UserDao.java:

    package com.m.ioc;

     

    public interface UserDao {

        public void say(int ll,double paipai);

    }

     

    UserDaoimp.java:

    package com.m.ioc;

     

    public class UserDaoimp implements UserDao{

        int l=4;double pai=3.14;

        public void say(int ll,double paipai)

        {

        l=ll;pai=paipai;

        System.out.println("底面周长是:"+(2*l*pai));

        System.out.println("底面积是:"+(l*l*pai));

        }

    }

     

    UserService.java:

    package com.m.ioc;

     

    public interface UserService {

        public void say(int h,double c);

    }

    UserServiceimp.java:

    package com.m.ioc;

     

    public class UserServiceimp implements UserService{

        double c=18.84;

        private UserDao userDao;

        public void setUserDao(UserDao userDao){

           this.userDao = userDao;

        }

        public void say(int h,double c){

        this.userDao.say(3,3.14);

        System.out.println("圆柱体积是:"+(c*h));

        }

    }

     

    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:p="http://www.springframework.org/schema/p"

        xsi:schemaLocation="http://www.springframework.org/schema/beans

            http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

        <!-- 将指定类配置给Spring,让Spring创建其对象的实例 -->

        <bean id="userDao" class="com.m.ioc.UserDaoimp" />

        <bean id="userService" class="com.m.ioc.UserServiceimp" >

        <property name="userDao" ref="userDao" />

    </bean>   

    </beans>

     

  • 相关阅读:
    【YBTOJ】守卫挑战
    【YBTOJ】【Luogu P6089】[JSOI2015]非诚勿扰
    【Luogu P4092】[HEOI2016/TJOI2016]树
    【YBTOJ】【Luogu P3232】[HNOI2013]游走
    【CodeForces 396B】On Sum of Fractions
    【P2579】【ZJTSC05】沼泽鳄鱼
    【YBTOJ】【USACO03MAR】最大均值
    【YBTOJ】防具布置
    VC 静态库与动态库(二)静态库创建与使用
    VC 静态库与动态库(一)介绍
  • 原文地址:https://www.cnblogs.com/1314-520/p/12635959.html
Copyright © 2020-2023  润新知