<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      聲微飯否

      博客園 首頁 新隨筆 聯系 訂閱 管理

      bean的作用范圍:

        bean標簽中有scope屬性來指定:

        singleton(siNGɡ?lt(?)n):單例模式   只創建一次  一致存在下去  

        prototype(?prōd??tīp):多例模式 每次使用都會重新創建

      bean生命周期中的兩個方法(bean標簽屬性):

        init-method: 執行構造后要進行的動作

        destory-method:銷毀前要進行的動作

      bean的生命周期是由容器來進行管理  容器關閉將銷毀bean ,不關閉前

      需要手動進行銷毀,ApplicationContext的子類ClassPathXmlApplicationsContext

      具有close方法。

      銷毀的方法只能作用于單例模式   多例模式 由垃圾回收機制管理。

      Spring的依賴注入:在ioc容器運行過程中動態將依賴關系注入到對象中

        1.通過構造方法注入:通過<construct-arg   ......   />   在bean內容中書寫

          標簽中的屬性: name:名稱  type:數據類型 index:索引  ref:賦值其他的bean類型  配置過的bean  value:值

          <bean name="date" class="java.util.Date"></bean>
          <bean id="student" class="com.offcn.entity.Student" >
              <constructor-arg name="id" value="1"></constructor-arg>
              <constructor-arg name="name" value="張三"></constructor-arg>
              <constructor-arg name="birthday" ref="date"></constructor-arg>
          </bean>

        2.通過setter注入:<property  name=""   ref= "">  書寫在bean內容中

      <bean id="student" class="com.offcn.entity.Student">
          <property name="id" value="2"></property>
          <property name="name" value="李四"></property>
      </bean>

         3.通過p標簽:實質還是setter方法注入   換頭部 在bean標簽的中:p:name=""

      <beans xmlns="http://www.springframework.org/schema/beans"201
          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.xsd">
          <bean id="student" class="com.offcn.entity.Student" p:id="1" p:name="李四"/>

      配置文件模塊化:將一個配置文件 分為多個配置文件

        創建applicationContext時可以傳入多個xml名,

        在主配置文件中導入其他的配置文件

      注:

        在同一個xml文件中id不能重復   主配置文件與其他配置文件的bean的id

      可以相同 ,但是后加載的bean會覆蓋前面的bean

      spring注入數組  集合 properites類型數據

      <bean id="commutils" class="com.offcn.entity.CommUtils">
      <property name="array" >
          <array>
                <value>111111</value>
                <value>111111</value>      
          </array>               
      </property>
      
      <property name="list" >
          <list>
                <value>111111</value>
                <value>111111</value>      
          </list>               
      </property>
          <property name="array" >
          <array>
                <entry key ="1111" value="11111"></value>
                <entry key = "111" value ="1111"></value>      
          </array>               
      </property>
      <property name="properites" >
          <props>
                <prop name = "11">111111</value>
                <prop name="222" >111111</value>      
          </props>               
      </property>

       

      Spring與jdbc的整合:

      Spring提供了ioc容器,管理jdbc操作數據庫過程中需要的的數據庫連接對象,同時spring提供了整合jdbc操作數據

      庫的工具類JdbcDaoSupport和模板工具JdbcTemplate,JdbcTemplate提供了大量操作數據庫的方法,

      配置文件

      注入的對象 必須是spring容器進行管理的對象

      得到數據源

       

       

       

      得到jdbcTemplate  注入 數據源的對象

       

      得到userDao   注入 jdbcTemplate  

       

      得到UserService對象  注入userDao對象

       

      JdbcTemplateapi

      1. query()查詢所以的數據

       

      1. queryForObject() 查詢單條記錄

       

       

       

      Spring注解配置IOC

        1.導入依賴 

         2.編寫配置文件:支持注解的頭部

      <?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:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd">
          <context:annotation-config/>
      </beans>

        3.編寫注解

      @Component("userDao")
      public class UserDaoImpl implements UserDao {
          public int add() {
              System.out.println("1111111111");
              return 0;
          }
      }

        4.在xml文件中掃描注解

       

       <context:component-scan base-package="com.offcn"></context:component-scan>

        5.測試

      public class Test {
          @org.junit.Test
          public void show(){
              ApplicationContext app = new ClassPathXmlApplicationContext("bean.xml");
              UserDao userDao = (UserDao) app.getBean("userDao");
              userDao.add();
          }
      }

       

      @Component:實例化當前對象  并使用spring來進行管理   value屬性與id作用相同 沒有的話就是當前類的名稱首字母小寫

      @Repository:編寫dao層的注解

      @Service:編寫service層的注解

      @Controller:編寫表現層的注解

      默認都是使用無參構造

      @Autowired:在類中注入需要使用的對象  一般寫在方法或變量上   多在變量上

        規則:根據類型進行注入 ,有且只能匹配一個,匹配多個或0個都會報錯

      @qualified:按照名稱進行匹配    與上者結合使用  不能單獨使用  value進行設置匹配的名稱

      java給spring提供的一個注解:

      @Resource:jdk1.6之后    name 進行設置    作用上面兩個的結合   先類型匹配在名稱 

      設置單例

      @Scope("singleton")

      生命周期的方法注解:

      @Predestory:對象銷毀前的動作

      @PostConstruct:調用構造后的動作

      <?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:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd">
      
          <context:annotation-config/>
      
      </beans>

      Spring中的注解:
      實例化對象注解:
      @Component:用于實例化對象 具有value屬性 寫在類的上方 當類不歸屬三層架構時使用
      @Service:service層對象
      @controller:
      @Repository:持久層對象
      依賴注入注解:
      @AutoWired:按照類型進行注入 匹配0個或多個都會報錯 當時用該注解來注入屬性時 set方法可以省略
      @Qualifier:在上者的基礎上在按照名稱進行匹配 具有 value屬性
      @Value:用于簡單類型的注入
      改變注入范圍的注解
      @Scope 
      其他:
      @Configuration:指定類為配置類取代xml文件 寫在類上
      @Bean?。簩懺诜椒ㄉ?表示該方法創建一個對象 并放在Spring容器中,具有value屬性
      @ComponentScan:執行spring初始化容器需要掃描的包 寫在類上
      @PropertySource:加載properites文件 寫在類上

      與junit整合
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration("classpath:.xml文件或配置類.class")
      posted on 2020-08-31 17:42  聲微飯否  閱讀(142)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 一边捏奶头一边高潮视频| 九九视频热最新在线视频| 日韩一区二区黄色一级片| 久久香蕉国产线看观看怡红院妓院| 亚洲国产无线乱码在线观看| 欧美人成在线播放网站免费| 日韩无专区精品中文字幕| 宝贝腿开大点我添添公口述视频| 99久久精品国产一区二区暴力| 激情综合色综合啪啪开心| 成人伊人青草久久综合网| 国产亚洲AV电影院之毛片| 国产精品亚洲аv无码播放| 色欲狠狠躁天天躁无码中文字幕| 色99久久久久高潮综合影院 | 国产欧美一区二区三区免费视频| 日韩有码精品中文字幕| 精品午夜福利在线视在亚洲| 好姑娘高清影视在线观看| 欧美成人片一区二区三区| 亚洲国产高清aⅴ视频| 亚洲卡1卡2卡新区网站| 国产91午夜福利精品| 亚洲精品国产无套在线观| 久久综合亚洲色一区二区三区| 国产欧美日韩亚洲一区二区三区| 国产高清吹潮免费视频| 精品无码国产日韩制服丝袜| 水蜜桃视频在线观看免费18| 欧美黑人巨大videos精品| 国产精品国产三级国产试看 | 116美女极品a级毛片| 中文字幕亚洲制服在线看| 果冻传媒一区二区天美传媒| 久久不见久久见免费视频观看| 国产中文三级全黄| 91偷自国产一区二区三区| 人人妻人人澡人人爽| 综合色在线| 国内揄拍国内精品人妻久久| 狠狠躁夜夜躁无码中文字幕|