<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ~~~ 常用IOC注解: Spring的IOC容器是Map結構 按照功能分類: 1.創建對象 * 作用和在XML配置文件中<bean>標簽實現的功能是一樣的 1) Component: 作用:用于把當前類對象存入spring容器 屬性: * value:指定bean的id.如果不寫,默認值是當前類名,且首字母小寫 2) Controller 一般用在表現層 3) Service 一般用在業務層 4) Repository 一般用在持久層 這4個注解的作用和屬性是一樣的 2.注入數據 Autowired: 作用: 自動注入.只要容器中有唯一的bean對象類型匹配成功,就能注入成功 如果ioc容器中沒有任何bean的類型和要注入的變量類型匹配,則報錯. 作用位置: 可以是變量上,也可以是方法上 細節: 在使用注解注入時,set方法就不是必須的了 Qualifier: 作用:在按照類中注入的基礎之上再按照名稱注入.它在給類成員注入時不能單獨使用.但是在給方法參數注入時可以 屬性: value:用于指定注入bean的id Resource 作用:直接按照bean的id注入.它可以獨立使用 屬性: name:用于指定bean的id 以上三個注入都能注入其他bean類型的數據,而基本類型和String類型無法使用以上注解實現. 別外,集合類型的注入只能通過XML來實現. value: 作用:用于注入基本類型和String類型的數據 屬性: value:用于指定數據的值.它可以使用spring中SpEL(也就是spring的el表達式) SpEL的寫法:${表達式} 3.作用范圍 作用和在bean標簽中使用scope屬性實現的功能是一樣的 Scope 作用:用于指定bean的作用范圍 屬性: value: 指定范圍的取值.常用取值:singleton,prototype,默認singleton singleton:單例 prototype: 多例 4.生命周期 作用和在bean標簽中使用init-method和destroy-methode的作用是一樣的. PreDestroy 作用:用于指定銷毀方式 PostContruct 作用:用于指定初始化方法 ~~~ ***** ~~~ <?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 https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!-- 告知spring在創建容器時要掃描的包,標簽是context --> <context:component-scan base-package="com.itheima"></context:component-scan> </beans> ~~~ ***** ~~~ package com.itheima.service.impl; import com.itheima.dao.IAccountDao; import com.itheima.service.IAccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.annotation.Resource; import java.util.*; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ /** * 賬戶的業務層實現類 */ //@Component //@Component(value = "accountService9") @Service(value = "accountService9") //@Scope("prototype") @Scope("singleton") public class AccountServiceImpl9 implements IAccountService { // // @Autowired //// @Qualifier("accountDao1") // @Qualifier("accountDao2") // private IAccountDao accountDao; // @Autowired // private IAccountDao accountDao;//多個IAccountDao對象時,造成系統錯誤 @Resource(name = "accountDao1") private IAccountDao accountDao; public void saveAccount() { accountDao.saveAccount(); } @PostConstruct public void init(){ System.out.println("生命周期,初始化...."); } @PreDestroy public void destroy(){ System.out.println("生命周期,對象銷毀"); } } ~~~ ***** ~~~ package com.itheima.dao.impl; import com.itheima.dao.IAccountDao; import org.springframework.stereotype.Repository; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ /** * 賬戶的持久層實現類 */ @Repository("accountDao1") public class AccountDaoImpl implements IAccountDao { public void saveAccount() { System.out.println("AccountDao 保存了賬戶1111!"); } } ~~~ ***** ~~~ package com.itheima.dao.impl; import com.itheima.dao.IAccountDao; import org.springframework.stereotype.Repository; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ /** * 賬戶的持久層實現類 */ @Repository("accountDao2") public class AccountDaoImpl2 implements IAccountDao { public void saveAccount() { System.out.println("AccountDao 保存了賬戶2222!"); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看