首页 > 其他分享 >自动装配注入与集合装配注入

自动装配注入与集合装配注入

时间:2023-07-13 11:56:58浏览次数:31  
标签:装配 applicationContext itcast xml boxuegu 集合 注入

自动装配注入特征

image


关键词 autowire
applicationContext.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.xsd">

    <bean class="dang.dao.impl.BookDaoImpl"/>
    <!--autowire属性:开启自动装配,通常使用按类型装配-->
    <bean id="bookService" class="dang.service.impl.BookServiceImpl" autowire="byType"/>

</beans>


集合装配注入

applicationContext.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.xsd">
    <bean id="bookDao" class="dang.dao.impl.BookDaoImpl">
        <!--数组注入-->
        <property name="array">
            <array>
                <value>100</value>
                <value>200</value>
                <value>300</value>
            </array>
        </property>
        <!--list集合注入-->
        <property name="list">
            <list>
                <value>itcast</value>
                <value>itheima</value>
                <value>boxuegu</value>
                <value>chuanzhihui</value>
            </list>
        </property>
        <!--set集合注入-->
        <property name="set">
            <set>
                <value>itcast</value>
                <value>itheima</value>
                <value>boxuegu</value>
                <value>boxuegu</value>
            </set>
        </property>
        <!--map集合注入-->
        <property name="map">
            <map>
                <entry key="country" value="china"/>
                <entry key="province" value="henan"/>
                <entry key="city" value="kaifeng"/>
            </map>
        </property>
        <!--Properties注入-->
        <property name="properties">
            <props>
                <prop key="country">china</prop>
                <prop key="province">henan</prop>
                <prop key="city">kaifeng</prop>
            </props>
        </property>
    </bean>
</beans>

标签:装配,applicationContext,itcast,xml,boxuegu,集合,注入
From: https://www.cnblogs.com/cpdd-dc/p/17550018.html

相关文章

  • DataTable转为List集合
    publicclassTabletoList{publicstaticList<T>TableToListModel<T>(DataTabledt)whereT:new(){//定义集合List<T>ts=newList<T>();//获得此模型的类型Type......
  • service 无法注入bean问题
    Noqualifyingbeanoftype'com.unqd.api.weituo.service.IamCustomerService'available:expectedatleast1beanwhichqualifiesasautowirecandidate.Dependencyannotations:{@org.springframework.beans.factory.annotation.Autowired(required=true......
  • .NET通过反射实现依赖注入
    设计通过反射实现依赖注入classProgram{//获取到当前程序的程序集,并且获取元数据信息publicstaticAssemblyassembly=Assembly.GetCallingAssembly();staticvoidMain(string[]args){vartypes=assembly.G......
  • 2、布尔注入
    获取数据库名长度?id=2'andlength(database())=8--+逐字猜解?id=2'andsubstr(database(),1,1)='s'--+?id=2'andsubstr(database(),2,1)='e'--+ 获取数据表长度?id=2'andlength((selecttable_namefrominformation_schema.tabl......
  • 子查询高级查询以及集合运算统计函数
    子查询单行子查询子查询部分的返回结果为单行的结果多行子查询子查询部分的返回结果为多行的结果,主要关键字有any,in,allany表示任意一个,在集合中有一个满足条件即可all所有,在集合中所有都满足即可in表示任意一个,在集合中有一个满足条件即可eg:s......
  • 19:vue3 依赖注入
    1、通过Prop逐级透传问题(传统老的方法只能逐级传递) 传统方式代码如下:App.vue1<template>2<h3>祖宗</h3>3<Parent:msg="msg"></Parent>4</template>56<script>7importParentfrom"./components/Parent.vue"......
  • 注解开发实现为第三方bean注入资源
     简单类型直接注入,使用Value注解 引用类型使用形参注入,只要在包下存在这个bean,容器就会自动装配注入,而且使用的是按类型装配......
  • 注解开发依赖注入
        ......
  • 1、union 注入
     判断前面有多少列?id=2'orderby3--+确定显示位?id=2'and'1'='2'unionselect1,2,3--+0、获取当前数据库名?id=2'and'1'='2'unionselect1,database(),3--+  1、查询数据表 基础语法: unionselect1,2,3fromtablewhere.........
  • WIMBoot是一种在Windows系统中实现文件镜像引导的技术。它允许将Windows镜像文件(WIM文
    WIMBoot是一种在Windows系统中实现文件镜像引导的技术。它允许将Windows镜像文件(WIM文件)直接注入到硬盘的压缩存储空间中,从而节省磁盘空间并提高系统性能。在WIMBoot中,WIM文件包含了完整的Windows操作系统及其组件。通常,WIM文件中的内容被解压缩并复制到硬盘上的普通文件系统中。......