zoukankan      html  css  js  c++  java
  • spring属性的三种注入方法

    (1)使用set方法:

    public class Book {
      private String bookname;
    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    xml配置:

    <bean id="book" class="com.example.propetys.Book">
    <!-- 注入属性值 name属性:值是你定义的属性的名称,value属性:设置的具体的值 -->
    <property name="bookname" value="九阳真经"></property>
    </bean>

    (2)有参数的构造

    public class PropertDemo1 {
        private String username;
        public PropertDemo1(String username) {
            this.username = username;
        }

    xml配置:

    <bean id="demo" class="com.example.propetys.PropertDemo1">
    <!-- 有参构造方法注入 -->
        <constructor-arg name="username" value="liuguxiia"></constructor-arg>
     </bean>

    (3)使用接口注入

    public Interface Dao{

      public void delete(String name);

    }

    public class DaoImpl implements Dao{

       private String name;

       public void delete(String name){

           this.name=name;

          }

    }

    在spring框架里,只允许前两种方式。

  • 相关阅读:
    如何用vue做计算器功能
    js反弹运动
    $.each的使用
    js文字滚动事件
    根据服务器时间,计算出时间轴的倒计时。
    时间格式转时间戳的几种方法
    匀速运动升级
    js匀速运动
    js图片滚动无缝衔接
    webFrame
  • 原文地址:https://www.cnblogs.com/xxdebug/p/8682349.html
Copyright © 2011-2022 走看看