国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

spring注解驅(qū)動(dòng)開發(fā)(一)

這篇具有很好參考價(jià)值的文章主要介紹了spring注解驅(qū)動(dòng)開發(fā)(一)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Spring常用注解(絕對經(jīng)典)

1、需要導(dǎo)入的spring框架的依賴
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.12.RELEASE</version>
    </dependency>
2、@Configuration

設(shè)置類為配置類

3、AnnotationConfigApplicationContext
  • 通過配置類獲取上下文環(huán)境applicationContext
  • 可以通過getBeanDefinitionNames()獲得配置類中配置的各類Bean
  • 也可以使用getBeanNamesForType()通過類型來獲得bean的name(id)
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String str : beanDefinitionNames) {
      System.out.println(str);
    }
4、@Bean
  • 注冊一個(gè)javaBean
  • 默認(rèn)用方法名作為Bean的id
  • 使用AnnotationConfigApplicationContext的實(shí)例 通過getBean來獲得這個(gè)Bean
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
  @Bean
  public Person person(){
    return new Person("lisi",20);
  }
}
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
    Person bean = applicationContext.getBean(Person.class);
    System.out.println(bean);
5、@ComponentScan

為配置類開啟組件掃描

  • 放在配置類的上方,指定掃描的包路徑如
@ComponentScan(value = "com.atguigu")
  • 還可以使用excludeFilter來設(shè)置類掃描規(guī)則如包含、排除,excludeFilter需要設(shè)置為一個(gè)數(shù)組
    排除
    包含使用excludeFilter,并為其設(shè)置一個(gè)過濾數(shù)組,來指定需要過濾掉那些組件
@Configuration
@ComponentScan(value = "com.atguigu",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,
        classes ={Controller.class,Service.class} )
})
public class MainConfig {
  @Bean
  public Person person(){
    return new Person("lisi",20);
  }
}

包含
包含使用includeFilter,包含里面需要設(shè)置使用默認(rèn)規(guī)則為false

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,
        classes ={Controller.class,Service.class} )},useDefaultFilters = false)
public class MainConfig {
  @Bean
  public Person person(){
    return new Person("lisi",20);
  }
}

還可以設(shè)置按給定類型過濾

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION,
                classes ={Controller.class,Service.class}),
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
                classes ={BookService.class})
},useDefaultFilters = false)
public class MainConfig {
  @Bean
  public Person person(){
    return new Person("lisi",20);
  }
}

其他可以設(shè)置的過濾方式還可以有:

  • 使用FilterType.ASPECTJ按照ASPECTJ表達(dá)式
  • 使用FilterType.REGEX按照REGEX正則表達(dá)式
  • 使用FilterType.CUSTOM按照自定義規(guī)則過濾(需要實(shí)現(xiàn)TypeFilter接口)

自定義過濾規(guī)則

public class MyTypeFilter implements TypeFilter {
  /*
  metadataReader:讀取到的當(dāng)前正在掃描的類的信息
  metadataReaderFactory:可以獲取到其他任何類的信息
   */

  @Override
  public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
    //獲取當(dāng)前類的注解信息
    AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
    //獲取當(dāng)前正在掃描的類的類信息
    ClassMetadata classMetadata = metadataReader.getClassMetadata();
    //獲取當(dāng)前類的資源(類的路徑)
    Resource resource = metadataReader.getResource();
    String className = classMetadata.getClassName();
    System.out.println(resource);
    System.out.println(className);
     if(className.contains("er")){
      return true;
    }
    return false;
  }
}

設(shè)置自定義規(guī)則

@Configuration
@ComponentScan(value = "com.atguigu",includeFilters = {
        @ComponentScan.Filter(type = FilterType.CUSTOM,
                classes = {MyTypeFilter.class})
},useDefaultFilters = false)
public class MainConfig {
  @Bean
  public Person person(){
    return new Person("lisi",20);
  }
}

測試代碼

@Test
  public void testbeans() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String str : beanDefinitionNames) {
      System.out.println(str);
    }
  }

測試結(jié)果

測試規(guī)則打印內(nèi)容

file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/bean/Person.class]
com.atguigu.bean.Person
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/config/MyTypeFilter.class]
com.atguigu.config.MyTypeFilter
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/controller/BookController.class]
com.atguigu.controller.BookController
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/dao/BookDAO.class]
com.atguigu.dao.BookDAO
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/service/BookService.class]
com.atguigu.service.BookService
file [/Users/human/Desktop/Project/05SpringMVC/spring-annotation/target/classes/com/atguigu/test/MainTest.class]
com.atguigu.test.MainTest

測試類打印過濾結(jié)果

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
person
myTypeFilter
bookController
bookService
6、@Controller

將類配置為Controller類

7、@Service

將類配置為service類

8、@Repository

將類配置為dao操作的類

9、@Component

將類配置為通用類組件

10、@Scope

調(diào)整bean的作用域范圍,默認(rèn)單實(shí)例,可以修改為多實(shí)例
Bean是默認(rèn)單實(shí)例的,通過指明prototype(多實(shí)例)和singleton(單實(shí)例)屬性指明是否單實(shí)例

  • prototype:多實(shí)例
  • singleton:單實(shí)例
  • request:同一次請求創(chuàng)建一個(gè)實(shí)例
  • session:同一個(gè)session創(chuàng)建一個(gè)實(shí)例
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
  //Bean是默認(rèn)單實(shí)例的,通過指明prototype(多實(shí)例)和singleton(單實(shí)例)屬性指明是是否單實(shí)例
  //prototype:多實(shí)例
  //singleton:單實(shí)例
  //request:同一次請求創(chuàng)建一個(gè)實(shí)例
  //session:同一個(gè)session創(chuàng)建一個(gè)實(shí)例
  @Scope("prototype")
  @Bean("person")//指定bean的自定義id
  public Person person(){
    return new Person("張三",20);
  }
}

測試

  @Test
  public void testbeans() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
	Object bean1 = applicationContext.getBean("person");
	Object bean2 = applicationContext.getBean("person");
    System.out.println(bean1==bean2);
  }

測試結(jié)果為false

11、@Lazy懶加載

實(shí)例默認(rèn)在容器創(chuàng)建時(shí)立即加載
使用@Lazy后,當(dāng)需要?jiǎng)?chuàng)建實(shí)例時(shí)才被加載

  • 不使用懶加載
    實(shí)體類構(gòu)造函數(shù)
  public Person(String name, Integer age) {
    System.out.println("給容器添加Person對象");

    this.name = name;
    this.age = age;
  }

測試代碼

@Test
  public void testbeans() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
    System.out.println("容器已創(chuàng)建完成");
    //沒有獲取類的代碼,單實(shí)際上類的實(shí)例已經(jīng)被加載進(jìn)容器了
  }

測試結(jié)果

給容器添加Person對象
容器已創(chuàng)建完成
  • 使用懶加載
@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }
}

測試代碼

@Test
  public void testbeans() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
    System.out.println("容器已創(chuàng)建完成");
    Object bean1 = applicationContext.getBean("person");//這一句出現(xiàn)后才加載Person類

  }

測試結(jié)果

給容器添加Person對象
容器已創(chuàng)建完成
12、@Conditional
  • 按一定條件注冊bean,滿足條件就給容器注冊bean,否則不注入
  • 要作為自定義條件,需要?jiǎng)?chuàng)建自定義condition類,并要實(shí)現(xiàn)Condition接口,并實(shí)現(xiàn)match方法
  • conditional不僅可以標(biāo)在方法上,還可以標(biāo)記在類上
//判斷是否是Linux系統(tǒng)的條件
//要作為自定義條件,要實(shí)現(xiàn)Condition接口,并實(shí)現(xiàn)match方法
//AnnotatedTypeMetadata:注釋信息
public class LinuxCondition implements Condition {
  @Override
  public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    //判斷l(xiāng)inux洗洗
    ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();
    //獲取類加載器
    ClassLoader classLoader = conditionContext.getClassLoader();
    //獲得當(dāng)前環(huán)境信息
    Environment environment = conditionContext.getEnvironment();
    //獲取到bean定義的注冊類
    BeanDefinitionRegistry registry = conditionContext.getRegistry();

    String OSproperty = environment.getProperty("os.name");
    if (OSproperty.contains("Mac OS X")){
      return true;
    }

    return false;
  }
}

另一個(gè)自定義條件

public class WindowsCondition implements Condition {
  @Override
  public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    Environment environment = conditionContext.getEnvironment();
    //獲取操作系統(tǒng)信息
    String OSproperty = environment.getProperty("os.name");
    if (OSproperty.contains("Window")){
      return true;
    }
    return false;
  }
}

配置類信息


@Configuration
@ComponentScan(value = "com.atguigu")
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }

  @Conditional({WindowsCondition.class})
  @Bean("male")
  public Person personMale(){
    return new Person("lisi",33);
  }

  @Conditional({LinuxCondition.class})
  @Bean("female")
  public Person personFemale(){
    return new Person("wanger",23);
  }
}

測試類信息

@Test
  public void testBeans() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);

    //獲取ioc容器的運(yùn)行環(huán)境
    ConfigurableEnvironment environment=applicationContext.getEnvironment();
    //獲取操作系統(tǒng)名稱
    String property = environment.getProperty("os.name");
    System.out.println(property);

    String[] namesForType = applicationContext.getBeanNamesForType(Person.class);
    for (String name:namesForType) {
      System.out.println(name);
    }

  }

測試結(jié)果

Mac OS X
person
female
13、給IOC容器中注冊組件的5種方法
  1. 包掃描+組件類上標(biāo)注注解:(@Controller,@Service,@Repository,@Component)
  2. @Bean:導(dǎo)入第三方包的組件
  3. @Import:快速給容器導(dǎo)入一個(gè)組件
    1)@Import(要導(dǎo)入到容器的組件),容器中就會(huì)自動(dòng)注冊這個(gè)逐漸,id默認(rèn)是全類名
    2)ImportSelector:返回需要導(dǎo)入的組件的全類名數(shù)組

4.使用ImportBeanDefinitionRegistrar
5.使用Spring提供的FactoryBean(工廠bean)注冊組件
1)默認(rèn)獲得的是工廠bean調(diào)用getObject創(chuàng)建的對象
2)要獲取工廠bean本身,需要給id前面加一個(gè)&標(biāo)識

14、@Import 快速導(dǎo)入一個(gè)類

使用@Import快速為配置類導(dǎo)入一個(gè)bean類
可以同時(shí)導(dǎo)入多個(gè)bean類
需要再配置類上方書寫

  • 創(chuàng)建被導(dǎo)入的bean類
public class Color {
}
public class Red {
}
  • 給配置類導(dǎo)入該類
@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class})//在這里進(jìn)行快速地導(dǎo)入,可以是數(shù)組形式
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }

  @Conditional({WindowsCondition.class})
  @Bean("male")
  public Person personMale(){
    return new Person("lisi",33);
  }

  @Conditional({LinuxCondition.class})
  @Bean("female")
  public Person personFemale(){
    return new Person("wanger",23);
  }
}

測試類代碼

 AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);

  @Test
  public void testImport(){
    printBeans(applicationContext);
  }

  private void printBeans(AnnotationConfigApplicationContext applicationContext){
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String name:beanDefinitionNames) {
      System.out.println(name);
    }
  }

測試結(jié)果

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
person
female
15、ImportSelector接口導(dǎo)入一個(gè)類
  • ImportSelector:返回需要導(dǎo)入的組件的全類名數(shù)組
  • 需要實(shí)現(xiàn)ImportSelector接口并改寫selectImports方法

創(chuàng)建需要被導(dǎo)入的類

public class Blue {
}
public class Yellow {
}

創(chuàng)建自己的Import類

public class MyImportSelect implements ImportSelector {
  @Override
  public String[] selectImports(AnnotationMetadata annotationMetadata) {
    //返回值是要導(dǎo)入到容器中的組件全類名
    //annotationMetadata:注解信息
    return new String[]{"com.atguigu.bean.Blue", "com.atguigu.bean.Yellow"};
  }
}

在配置類中設(shè)置@Import導(dǎo)入的自定義類選擇器

注意:@Import({Color.class, Red.class,MyImportSelect.class})

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class})
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }

  @Conditional({WindowsCondition.class})
  @Bean("male")
  public Person personMale(){
    return new Person("lisi",33);
  }

  @Conditional({LinuxCondition.class})
  @Bean("female")
  public Person personFemale(){
    return new Person("wanger",23);
  }
}

測試代碼

AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);

  @Test
  public void testImport(){
    printBeans(applicationContext);
  }

  private void printBeans(AnnotationConfigApplicationContext applicationContext){
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String name:beanDefinitionNames) {
      System.out.println(name);
    }
  }

測試結(jié)果
Color,Red,Blue,Yellow都有了

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female
16、使用ImportBeanDefinitionRegistrar接口導(dǎo)入類

自定義導(dǎo)入的類定義,需要實(shí)現(xiàn)ImportBeanDefinitionRegistrar接口,并重寫 registerBeanDefinitions方法

創(chuàng)建一個(gè)需要被注入的類

public class RainBow {
}

創(chuàng)建自定義的注冊類信息類

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
  //annotationMetadata:當(dāng)前類的注解信息
  //beanDefinitionRegistry:beanDefinition注冊類
  //把所有需要添加到容器中的bean,調(diào)用beanDefinitionRegistry.registerBeanDefinition手動(dòng)注冊類
  @Override
  public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
    boolean red = beanDefinitionRegistry.containsBeanDefinition("com.atguigu.bean.Red");//判斷定義中是否有紅色
    boolean blue = beanDefinitionRegistry.containsBeanDefinition("com.atguigu.bean.Blue");//判斷定義中是否有藍(lán)色
    if(red && blue){
      //指定bean名
      RootBeanDefinition rainbowDefinition = new RootBeanDefinition(RainBow.class);
      //注冊了一個(gè)bean,并指定了一個(gè)類名(別名)
      beanDefinitionRegistry.registerBeanDefinition("rainbow", rainbowDefinition);
    }
  }
}

在配置類中進(jìn)行配置
注意:@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }

  @Conditional({WindowsCondition.class})
  @Bean("male")
  public Person personMale(){
    return new Person("lisi",33);
  }

  @Conditional({LinuxCondition.class})
  @Bean("female")
  public Person personFemale(){
    return new Person("wanger",23);
  }
}

測試類

 @Test
  public void testImport(){
    printBeans(applicationContext);
  }

  private void printBeans(AnnotationConfigApplicationContext applicationContext){
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String name:beanDefinitionNames) {
      System.out.println(name);
    }
  }

測試結(jié)果
顯示了rainbow

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female
rainbow
17、使用FactoryBean接口導(dǎo)入類

創(chuàng)建自定義工廠類,實(shí)現(xiàn)FactoryBean接口,并改寫一下方法
getObject() //返回工廠生產(chǎn)的類對象
getObjectType()//返回工廠生產(chǎn)的類類型
isSingleton() //返回單例

創(chuàng)建自定義工廠類
這里實(shí)現(xiàn)FactoryBean接口,實(shí)現(xiàn)三個(gè)方法,注意泛型中使用Color類


public class ColorFactory implements FactoryBean<Color> {
  //返回一個(gè)Color對象,這個(gè)對象會(huì)添加到容器中

  @Override
  public Color getObject() throws Exception {
    System.out.println("color factory generate a instance");
    return new Color();
  }

  @Override
  public Class<?> getObjectType() {
    return Color.class;
  }


  @Override
  public boolean isSingleton() {
    //true:返回單例,在容器中保存一份
    //false:返回多份類實(shí)例,每次獲取工廠bean都會(huì)創(chuàng)建一個(gè)新的對象
    return false;
  }
}

在配置類中定義這個(gè)類組件
注意:
@Bean
public ColorFactory colorFactoryBean(){
return new ColorFactory();
}
}

@Configuration
@ComponentScan(value = "com.atguigu")
@Import({Color.class, Red.class,MyImportSelect.class,MyImportBeanDefinitionRegistrar.class})
public class MainConfig {
//  @Scope("prototype")
  @Lazy
  @Bean("person")//指定bean的自定義id
  public Person person(){

    return new Person("張三",20);
  }

  @Conditional({WindowsCondition.class})
  @Bean("male")
  public Person personMale(){
    return new Person("lisi",33);
  }

  @Conditional({LinuxCondition.class})
  @Bean("female")
  public Person personFemale(){
    return new Person("wanger",23);
  }

  @Bean
  public ColorFactory colorFactoryBean(){
    return new ColorFactory();
  }
}

測試類

public class MainTest {
  AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);

  @Test
  public void testImport(){
    printBeans(applicationContext);

    //工廠bean獲取的是調(diào)用的是getObject創(chuàng)建的對象(Color類)
    Object bean1 = applicationContext.getBean("colorFactoryBean");
    Object bean2 = applicationContext.getBean("colorFactoryBean");

    System.out.println(bean1);
    System.out.println(bean2.getClass());//class com.atguigu.bean.Color
    System.out.println(bean1==bean2);
  }

  private void printBeans(AnnotationConfigApplicationContext applicationContext){
    String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
    for (String name:beanDefinitionNames) {
      System.out.println(name);
    }
  }

測試結(jié)果文章來源地址http://www.zghlxwxcb.cn/news/detail-623245.html

org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig
bookController
bookDAO
bookService
com.atguigu.bean.Color
com.atguigu.bean.Red
com.atguigu.bean.Blue
com.atguigu.bean.Yellow
person
female
colorFactoryBean
rainbow
color factory generate a instance
color factory generate a instance
com.atguigu.bean.Color@79c97cb
class com.atguigu.bean.Color
false

到了這里,關(guān)于spring注解驅(qū)動(dòng)開發(fā)(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • spring注解驅(qū)動(dòng)開發(fā)(一)

    Spring常用注解(絕對經(jīng)典) 1、需要導(dǎo)入的spring框架的依賴 2、@Configuration 設(shè)置類為配置類 3、AnnotationConfigApplicationContext 通過配置類獲取上下文環(huán)境applicationContext 可以通過getBeanDefinitionNames()獲得配置類中配置的各類Bean 也可以使用getBeanNamesForType()通過類型來獲得bean的name(id)

    2024年02月14日
    瀏覽(20)
  • SSM框架的學(xué)習(xí)與應(yīng)用(Spring + Spring MVC + MyBatis)-Java EE企業(yè)級應(yīng)用開發(fā)學(xué)習(xí)記錄(第五天)MyBatis的注解開發(fā)

    SSM框架的學(xué)習(xí)與應(yīng)用(Spring + Spring MVC + MyBatis)-Java EE企業(yè)級應(yīng)用開發(fā)學(xué)習(xí)記錄(第五天)MyBatis的注解開發(fā)

    ? 昨天我們深入學(xué)習(xí)了 MyBatis多表之間的關(guān)聯(lián)映射,了解掌握了一對一關(guān)聯(lián)映射,一對多關(guān)聯(lián)映射,嵌套查詢方式以及嵌套結(jié)果方式,掌握了緩存機(jī)制的一級緩存,二級緩存等概念,也使用了代碼進(jìn)行復(fù)現(xiàn)理解 。但是都是基于XML配置文件的方式來實(shí)現(xiàn)的,現(xiàn)在我們要學(xué)習(xí)一下

    2024年02月11日
    瀏覽(58)
  • spring注解驅(qū)動(dòng)開發(fā)(BEAN注冊方式與生命周期)

    spring注解驅(qū)動(dòng)開發(fā)(BEAN注冊方式與生命周期)

    目錄 容器中注冊BEAN的方式 BEAN生命周期 包掃描+組件標(biāo)注注解 @ComponentScan(basePackages = {\\\"com.an.spring.condition\\\"}) @Service @Component @Controller @Repository @BEan方式【導(dǎo)入第三方包里面的組件】 @Import快速給容器中導(dǎo)入一個(gè)組件。 1)、@IMport(要導(dǎo)入到容器中的組件),容器就會(huì)注入這個(gè)組

    2024年02月07日
    瀏覽(48)
  • Spring注解驅(qū)動(dòng)開發(fā)之常用注解案例_告別在XML中配置Bean

    注解驅(qū)動(dòng)開發(fā)就是不再使用Spring的bean.xml文件,改為純使用注解的方式開發(fā) @Configuration 此注解為配置類注解,相當(dāng)于spring.xml文件,即配置類==配置文件 @Bean 給容器中注冊一個(gè)Bean;類型為返回值的類型,id默認(rèn)是用方法名作為id 示例 Person類(后續(xù)注解配置類中都會(huì)以此類舉例),

    2024年01月21日
    瀏覽(28)
  • QT學(xué)習(xí)筆記-Linux ARM環(huán)境下實(shí)現(xiàn)QT程序通過ODBC驅(qū)動(dòng)訪問SQLServer數(shù)據(jù)庫

    QT學(xué)習(xí)筆記-Linux ARM環(huán)境下實(shí)現(xiàn)QT程序通過ODBC驅(qū)動(dòng)訪問SQLServer數(shù)據(jù)庫

    在嵌入式系統(tǒng)中使用QT開發(fā)上位機(jī)應(yīng)用時(shí)不可避免的會(huì)涉及訪問各種數(shù)據(jù)庫的場景,而服務(wù)端數(shù)據(jù)庫的種類則有多種可能(Oracle、Postgresql、MySql、SQLServer),本文就介紹一下如何實(shí)現(xiàn)在Linux Arm環(huán)境下實(shí)現(xiàn)QT程序通過ODBC驅(qū)動(dòng)訪問SQLServer數(shù)據(jù)庫的。 開發(fā)環(huán)境操作系統(tǒng):windows10專業(yè)

    2024年02月12日
    瀏覽(31)
  • [開發(fā)|數(shù)據(jù)庫] java程序人大金倉數(shù)據(jù)庫適配筆記

    需要去人大金倉https://www.kingbase.com.cn/qd/index.htm下載linux版iso文件和授權(quán)文件(license-企業(yè)版-90天)。 iso文件需要掛載在指定目錄下。 參考:(https://www.cnblogs.com/bluestorm/p/16941812.html)。 人大金倉數(shù)據(jù)庫安裝過程中出現(xiàn)亂碼/內(nèi)容不顯示是因?yàn)閖dk版本不匹配,通過asdf更換java版本為

    2024年02月12日
    瀏覽(124)
  • 基于Spring注解 + MyBatis + Servlet 實(shí)現(xiàn)數(shù)據(jù)庫交換的小小Demo

    基于Spring注解 + MyBatis + Servlet 實(shí)現(xiàn)數(shù)據(jù)庫交換的小小Demo

    配置數(shù)據(jù)庫連接信息 db.properties 配置web.xml 配置logback.xml配置文件 配置applicationContext.xml 里面的bean 配置myBatis核心配置文件mybatis-config.xml 創(chuàng)建實(shí)體類對象User 創(chuàng)建LoginServlet響應(yīng)前端的數(shù)據(jù) 創(chuàng)建UserService 接口 創(chuàng)建UserMapper接口 創(chuàng)建UserServiceImpl 接口實(shí)現(xiàn)類 按照這樣的方式進(jìn)行拼接

    2024年02月02日
    瀏覽(30)
  • Spring AOP官方文檔學(xué)習(xí)筆記(二)之基于注解的Spring AOP

    1.@Aspect注解 (1) @Aspect注解用于聲明一個(gè)切面類,我們可在該類中來自定義切面,早在Spring之前,AspectJ框架中就已經(jīng)存在了這么一個(gè)注解,而Spring為了提供統(tǒng)一的注解風(fēng)格,因此采用了和AspectJ框架相同的注解方式,這便是@Aspect注解的由來,換句話說,在Spring想做AOP框架之前,

    2023年04月17日
    瀏覽(25)
  • Qt+MySql開發(fā)筆記:Qt5.9.3的msvc2017x64版本編譯MySql8.0.16版本驅(qū)動(dòng)并Demo連接數(shù)據(jù)庫測試

    Qt+MySql開發(fā)筆記:Qt5.9.3的msvc2017x64版本編譯MySql8.0.16版本驅(qū)動(dòng)并Demo連接數(shù)據(jù)庫測試

    若該文為原創(chuàng)文章,轉(zhuǎn)載請注明原文出處 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/130381428 紅胖子網(wǎng)絡(luò)科技博文大全:開發(fā)技術(shù)集合(包含Qt實(shí)用技術(shù)、樹莓派、三維、OpenCV、OpenGL、ffmpeg、OSG、單片機(jī)、軟硬結(jié)合等等)持續(xù)更新中… ??mysql驅(qū)動(dòng)版本msvc2015x32版本調(diào)

    2023年04月26日
    瀏覽(50)
  • Java企業(yè)級開發(fā)學(xué)習(xí)筆記(4.4)Spring Boot加載自定義配置文件

    Java企業(yè)級開發(fā)學(xué)習(xí)筆記(4.4)Spring Boot加載自定義配置文件

    創(chuàng)建 Spring Boot 項(xiàng)目 單擊【創(chuàng)建】按鈕 在 resources 里創(chuàng)建 myconfig.properties 文件 設(shè)置文件編碼 設(shè)置學(xué)生的四個(gè)屬性值 在 cn.kox.boot 包里創(chuàng)建config子包,在子包里創(chuàng)建 StudentConfig 打開自帶的測試類 ConfigDemo01ApplicationTests 注入學(xué)生配置實(shí)體,創(chuàng)建 testStudentConfig() 測試方法,在里面輸

    2024年02月08日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包