• Spring再接触 集合注入


    beans.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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
      <bean name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
          <property name="sets">
              <set>
                  <value>1</value>
                  <value>2</value>
              </set>
          </property>
          <property name="lists">
              <list>
                  <value>1</value>
                  <value>2</value>
                  <value>3</value>
              </list>
          </property>
          <property name="maps">
              <map>
                  <entry key="1" value="1"></entry>
                  <entry key="2" value="2"></entry>
                  <entry key="3" value="3"></entry>
                  <entry key="4" value="4"></entry>
              </map>
          </property>
      </bean>
    
      <bean id="userService" class="com.bjsxt.service.UserService">
      <!-- 
          <property name="userDAO">
              <ref bean="userDAO"/>
          </property>
           -->
           <constructor-arg>
               <ref bean="userDAO"/>
           </constructor-arg>
      </bean>
    
    
    </beans>

    userDAOimpl

    package com.bjsxt.dao.impl;
    
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    
    import com.bjsxt.dao.UserDAO;
    import com.bjsxt.model.User;
    
    public class UserDAOImpl implements UserDAO {
        /* (non-Javadoc)
         * @see com.bjsxt.dao.UserDAO#save(com.bjsxt.model.User)
         */
        private Set<String> sets;
        private List<String> lists;
        private Map<String , String> maps;
        
        
        public Set<String> getSets() {
            return sets;
        }
    
    
    
        public void setSets(Set<String> sets) {
            this.sets = sets;
        }
    
    
    
        public List<String> getLists() {
            return lists;
        }
    
    
    
        public void setLists(List<String> lists) {
            this.lists = lists;
        }
    
    
    
        public Map<String, String> getMaps() {
            return maps;
        }
    
    
    
        public void setMaps(Map<String, String> maps) {
            this.maps = maps;
        }
    
    
    
        public UserDAOImpl() {
        }
        
        
    
        public void save(User user) {
            System.out.println("user saved!");
        }
        
        @Override
        public String toString() {
            return "sets size:" + sets.size() + "| lists size:" + lists.size() + "| maps size:" + maps.size() ; 
        }
    
    }

    Test

    @Test
        public void testAdd() throws Exception {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
            UserDAO u1 = (UserDAO)ctx.getBean("userDAO");
            System.out.println(u1);
        }
  • 相关阅读:
    MT【111】画图估计
    MT【110】巧设法向量解决距离问题
    a++为啥不能用作左值
    qt之正则表达式
    QtWebkit中如何将网页内容转为图片
    数字图像去雾快速算法
    基于AdaBoost的人脸检测
    谈谈自动瘦脸和自动眼睛放大算法
    QT_opengl_gluPerspective没有定义的处理方法
    OpenGL框架+QT版
  • 原文地址:https://www.cnblogs.com/frankzone/p/9613231.html
Copyright © 2020-2023  润新知