转载自https://www.cnblogs.com/zzb-yp/p/9968849.html

Spring中XML文件配置Bean的简单示例,如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="color">
<value>红色</value>
</property>
</bean>

注:在上述例子中,<property>标签对应的属性类型是基础数据类型,Spring容器会将它的字面值“红色”自动转化成Bean对象中属性所对应到的字符串类型,但是除了字符串、整型等这些基础数据类型外,还有Bean、List、Set、Map、Properties等类型。

注:如果所赋值内容可以被XML文件解析,如:<、&、>、“、‘等,则需要进行特殊处理方可被正确赋值,如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="type">
<value><![CDATA[XX&55]]></value>
</property>
<property name="xml">
<value>&lt:开尖括号</value>
</property>
</bean>

注:上述中Bean对象两个属性赋值分别为XX&55和<开尖括号,使用<![CDATA[文本内容]]>使得文本内容当作普通文本进行处理,&lt;是<的转义格式,另外还有&gt;是>的转义、&amp;是&的转义、&quot;是“的转义、&apos;是‘的转义

注:<value></value>中带有空格则赋予的值将包括空格,如果想要将null赋给属性,如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="color">
<null/>
</property>
</bean>

1、Bean对象中Bean属性在XML文件中的配置如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="boss">
<ref bean="boss"></ref>
</property>
</bean>
<bean id="boss" class="com.smart.ditype.Boss"/>

注:如果①Bean只被②Bean引用而不被其他任何Bean引用,那么可以将①Bean以内部Bean的方式注入到②Bean,如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="boss">
<bean class="com.smart.ditype.Boss">
<property name="color">
<value>红色</value>
</property>
</bean>
</property>
</bean>

2、Bean对象中集合属性在XML文件中的配置如下:

<bean id="car" class="com.smart.ditype.Car">
<property name="list">
<list>
<value>看报</value>
<value>赛车</value>
</list>
</property>
<property name="set">
<set>
<value>踢球</value>
<value>打牌</value>
</set>
</property>
<property name="map">
<map>
<entry>
<key><value>am</value></key>
<value>见客户</value>
</entry>
</map>
</property>
<property name="properties">
<props>
<prop key="mail">17896532@123.com</prop>
</props>
</property>
</bean>

转载自https://blog.csdn.net/xiao1_1bing/article/details/81086116

一、property标签:
英文解释:Bean definitions can have zero or more properties. Property elements correspond to JavaBean setter methods exposed by the bean classes. Spring supports primitives, references to other beans in the same or related factories, lists, maps and properties.

上句翻译:Bean定义可以具有零个或多个属性。属性元素对应于bean类公开的JavaBean setter方法。 Spring支持原语,对相同或相关工厂中的其他bean的引用,列表,映射和属性。

二、property标签属性(name为属性名,type为=“”引号里面的类型,use为是否必须出现):
1、name="name"     type="xsd:string"     use="required"
英文解释:The name of the property, following JavaBean naming conventions.

上句翻译:遵循JavaBean命名约定的属性名称。(为Java中setAaaa去掉set,实际上就是要注入的东西)

2、name="ref"     type="xsd:string"
英文解释:A short-cut alternative to a nested "<ref bean='...'/>".

上句翻译:嵌套“<ref bean ='...'/>”的快捷替代方法。(bean的id)

3、name="value"       type="xsd:string"
英文解释:A short-cut alternative to a nested "<value>...</value>" element.

上句翻译:嵌套“<value> ... </ value>”元素的快捷替代方法。

三、property标签的下一层标签(ref为标签名字,minOccurs为最小出现次数,minOccurs为最大出现次数)
1、<xsd:element ref="description" minOccurs="0"/>

2、choice为多选一

<xsd:choice minOccurs="0" maxOccurs="1">

<xsd:element ref="meta"/>

<xsd:element ref="bean"/>

<xsd:element ref="ref"/>

<xsd:element ref="idref"/>

<xsd:element ref="value"/>

<xsd:element ref="null"/>

<xsd:element ref="array"/>

<xsd:element ref="list"/>

<xsd:element ref="set"/>

<xsd:element ref="map"/>

<xsd:element ref="props"/>

</xsd:choice>

(1)、meta标签(查看我的其他文章中meta)
(2)、bean标签(查看我的其他文章中bean)
(3)、ref标签
英文解释:Defines a reference to another bean in this factory or an external factory (parent or included factory).

上句翻译:定义对此工厂或外部工厂(父工厂或包含工厂)中的另一个bean的引用。

ref标签属性:
      name="bean"     type="xsd:string"
      英文解释:The name of the referenced bean.

上句翻译:引用bean的名称。

name="local"       type="xsd:IDREF"
      英文解释:The name of the referenced bean. The value must be a bean ID and thus can be checked by the XML parser. This is therefore the preferred technique for referencing beans within the same bean factory XML file.

上句翻译:引用bean的名称。该值必须是bean ID,因此可以由XML解析器检查。因此,这是在同一个bean工厂XML文件中引用bean的首选技术。

name="parent"          type="xsd:string"
      英文解释:The name of the referenced bean in a parent factory.

上句翻译:父工厂中引用的bean的名称。

(4)、idref标签
英文解释:The id of another bean in this factory or an external factory (parent or included factory). While a regular 'value' element could instead be used for the same effect, using idref in this case allows validation of local bean ids by the XML parser, and name completion by supporting tools.

上句翻译:此工厂或外部工厂(父工厂或包含工厂)中另一个bean的ID。虽然常规的'value'元素可以用于相同的效果,但在这种情况下使用idref允许XML解析器验证本地bean ID,并通过支持工​​具命名完成。

idref标签属性:
          name="bean"       type="xsd:string"
          英文解释:The name of the referenced bean.

中文翻译:引用bean的名称。

name="local"         type="xsd:IDREF"
          英文解释:The name of the referenced bean. The value must be a bean ID and thus can be checked by the XML parser. This is therefore the preferred technique for referencing beans within the same bean factory XML file.

中文翻译:引用bean的名称。该值必须是bean ID,因此可以由XML解析器检查。因此,这是在同一个bean工厂XML文件中引用bean的首选技术。

(5)、value标签
英文解释:Contains a string representation of a property value. The property may be a string, or may be converted to the required type using the JavaBeans PropertyEditor machinery. This makes it possible for application developers to write custom PropertyEditor implementations that can convert strings to arbitrary target objects. Note that this is recommended for simple objects only. Configure more complex objects by populating JavaBean properties with references to other beans.

中文翻译:包含属性值的字符串表示形式。该属性可以是字符串,也可以使用JavaBeans PropertyEditor机制转换为所需类型。这使得应用程序开发人员可以编写可以将字符串转换为任意目标对象的自定义PropertyEditor实现。请注意,建议仅用于简单对象。通过使用对其他bean的引用填充JavaBean属性来配置更复杂的对象。

value标签属性:
           name="type"           type="xsd:string"
           英文解释:The exact type that the value should be converted to. Only needed if the type of the target property or constructor argument is too generic: for example, in case of a collection element.

上句翻译:应将值转换为的确切类型。仅在目标属性或构造函数参数的类型过于通用时才需要:例如,在集合元素的情况下。

(6)、null标签
英文解释:Denotes a Java null value. Necessary because an empty "value" tag will resolve to an empty String, which will not be resolved to a null value unless a special PropertyEditor does so.

上句翻译:表示Java null值。必要是因为空的“value”标记将解析为空字符串,除非特殊的PropertyEditor这样做,否则不会将其解析为空值。

(7)、array标签
英文解释:An array can contain multiple inner bean, ref, collection, or value elements. This configuration element will always result in an array, even when being defined e.g. as a value for a map with value type Object.

上句解释:数组可以包含多个内部bean,ref,collection或value元素。即使在被定义时,该配置元素也总是产生一个数组。作为值类型为Object的映射的值。

array标签属性:
        name="merge"         default="default"         type="defaultable-boolean"
        英文解释:Enables/disables merging for collections when using parent/child beans.

上句翻译:使用父/子bean时,启用/禁用合并集合。

name="value-type"     type="xsd:string"(其中:array,list,set,都含有这个属性)
        英文解释:The default Java type for nested values. Must be a fully qualified class name.

上句翻译:嵌套值的默认Java类型。必须是完全限定的类名。

array标签下一层标签(其中:array,list,set,都含有这个)
       <xsd:group ref="collectionElements"/>

(8)、list标签
英文解释:A list can contain multiple inner bean, ref, collection, or value elements. A list can also map to an array type; the necessary conversion is performed automatically.

上句翻译:列表可以包含多个内部bean,ref,collection或value元素。列表也可以映射到数组类型;必要的转换是自动执行的。

list标签属性:
           name="merge"       default="default"          type="defaultable-boolean"
          英文解释:Enables/disables merging for collections when using parent/child beans.

上句翻译:使用父/子bean时,启用/禁用合并集合。

(9)、set标签:
英文解释:A set can contain multiple inner bean, ref, collection, or value elements.

上句翻译:集合可以包含多个内部bean,ref,collection或value元素。

set标签属性:
           name="merge"       default="default"          type="defaultable-boolean"
          英文解释:Enables/disables merging for collections when using parent/child beans.

上句翻译:使用父/子bean时,启用/禁用合并集合。

(10)、map标签
英文解释:A mapping from a key to an object. Maps may be empty.

上句翻译:从键到对象的映射。地图可能为空。

map标签属性:
           name="merge"       default="default"          type="defaultable-boolean"
          英文解释:Enables/disables merging for collections when using parent/child beans.

上句翻译:使用父/子bean时,启用/禁用合并集合。

name="value-type"      type="xsd:string"
        英文解释:The default Java type for nested values. Must be a fully qualified class name.

上句翻译:嵌套值的默认Java类型。必须是完全限定的类名。

name="key-type"      type="xsd:string"
         英文解释:The default Java type for nested entry keys. Must be a fully qualified class name.

上句翻译:嵌套条目键的默认Java类型。必须是完全限定的类名。

map标签下一层标签:
        <xsd:element ref="description" minOccurs="0"/>(其他文章有)

<xsd:element ref="entry"/>
         英文解释:A map entry can be an inner bean, ref, value, or collection. The key of the entry is given by the "key" attribute or child element.

上句翻译:映射条目可以是内部bean,ref,值或集合。条目的键由“key”属性或子元素给出。

entry标签属性:
                name="key"     type="xsd:string"
                英文解释:Each map element must specify its key as attribute or as child element. A key attribute is always a String value.

上句翻译:每个map元素必须将其键指定为attribute或child元素。键属性始终是String值。

name="key-ref"      type="xsd:string"
                英文解释:A short-cut alternative to a to a "key" element with a nested "<ref bean='...'/>".

上句翻译:带有嵌套“<ref bean ='...'/>”的“key”元素的快捷替代方法。

name="value"         type="xsd:string"
                 英文解释:A short-cut alternative to a nested "<value>...</value>" element.

上句翻译:嵌套“<value> ... </ value>”元素的快捷替代方法。

name="value-ref"      type="xsd:string"
                 英文解释:A short-cut alternative to a nested "<ref bean='...'/>".

上句翻译:嵌套“<ref bean ='...'/>”的快捷替代方法。

entry标签下次层标签:
               <xsd:element ref="key" minOccurs="0"/>

<xsd:group ref="collectionElements"/>

(11)、props标签
英文解释:Props elements differ from map elements in that values must be strings. Props may be empty.

上句翻译:属性元素与map元素的不同之处在于,值必须是字符串。属性可能是空的。

props标签属性:
           name="merge"       default="default"          type="defaultable-boolean"
          英文解释:Enables/disables merging for collections when using parent/child beans.

上句翻译:使用父/子bean时,启用/禁用合并集合。

name="value-type"      type="xsd:string"
        英文解释:The default Java type for nested values. Must be a fully qualified class name.

上句翻译:嵌套值的默认Java类型。必须是完全限定的类名。

props标签下一层标签:
        ref="prop"
        英文解释:The string value of the property. Note that whitespace is trimmed off to avoid unwanted whitespace caused by typical XML formatting.

上句翻译:属性的字符串值。(就是成员变量)请注意,修剪空白以避免由典型的XML格式化导致的不需要的空白。

<prop>标签属性:
       name="key"     type="xsd:string"        use="required"
       英文解释:The key of the property entry.

上句翻译:属性入口的关键。
---------------------
作者:冰凌其
来源:CSDN
原文:https://blog.csdn.net/xiao1_1bing/article/details/81086116
版权声明:本文为博主原创文章,转载请附上博文链接!

Spring 标签纸property的更多相关文章

  1. 使用Spring标签库

    A.Spring标签库 Web项目若使用Spring Web MVC并使用JSP作为表现的话.从Spring2.0版本开始提供一套标签库可供使用. 使用标签库无非是易于开发,维护之类云云.这里就不阐述 ...

  2. 使用Spring标签<form:textarea>时,用readonly=“readonly”属性时不起作用。

    最近的一个项目用到了Spring标签<form:textarea>,当在设置其只读属性时,使用readonly="readonly"不起作用,还是能修改内容. 在网上找 ...

  3. Spring标签@Aspect-实现面向方向编程(@Aspect的多数据源自动加载)——SKY

    从Spring 2.0开始,可以使用基于schema及@AspectJ的方式来实现AOP.由于@Aspect是基于注解的,因此要求支持注解的5.0版本以上的JDK. 环境要求:    1. mybit ...

  4. assembly打包插件引发的自定义spring标签找不到声明的错误

    异常信息:通配符的匹配很全面, 但无法找到元素 的声明. 报的异常信息是关于我们使用的一个自定义的spring标签,这个异常通常的原因可能是读取不到自定义标签的映射. 到META-INF目录下找一下是 ...

  5. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  6. Spring标签<mvc:annotation-driven/>解读

    一.AnnotationDrivenBeanDefinitionParser 通常如果我们希望通过注解的方式来进行Spring MVC开发,我们都会在***-servlet.xml中加入<mvc ...

  7. 通过spring工厂读取property配置文件

    /** * Created by ywq on 2016/6/30. */ @Named public class PropertyConfig { private static AbstractBe ...

  8. spring+jidi读取property的配置文件

    在Spring项目中,你可能需要从properties文件中读入配置注入到bean中,例如数据库连接信息,memcached server的地址端口信息等,这些配置信息最好独立于jar包或者war包, ...

  9. 自定义Spring标签

    写了好几次了,结果一段时间之后就忘记了自己有写好的example,但是最后还是决定重新写一遍,把这个步骤记录下来 首先看整个项目结构 从transaction.xml开始,虽然图上报错了,实际上运行并 ...

随机推荐

  1. Dubbo系列之 (四)服务订阅(1)

    辅助链接 Dubbo系列之 (一)SPI扩展 Dubbo系列之 (二)Registry注册中心-注册(1) Dubbo系列之 (三)Registry注册中心-注册(2) Dubbo系列之 (四)服务订 ...

  2. Scala集合操作中的几种高阶函数

    Scala是函数式编程,这点在集合操作中大量体现.高阶函数,也就是能够接收另外一个函数作为参数的函数. 假如现在有一个需要是将List集合中的每个元素变为原来的两倍,现在来对比Java方式实现和Sca ...

  3. python3在科学计算中的三种常用数据结构

    在科学研究中,数据运算是必不可少的,下面介绍python语言在科学计算中常用的数据结构和运算函数. 主要数据结构: (1)列表,用中括号表示,元素之间逗号分隔,每个元素可以是数字,字符,也可以是列表, ...

  4. springMVC入门(四)------参数绑定与返回值类型

    简介 从之前的介绍,已经可以使用springMVC完成完整的请求.返回数据的功能. 待解决的问题:如何将数据传入springMVC的控制器进行后续的处理,完成在原生servlet/jsp开发中Http ...

  5. java进阶(10)--String(StringBuff、StringBuilder)

    一.基本概念 1.String为引用数据类型,使用双引号 2.字符串数组存储在方法区的内存池,因为开发过程种使用过于频繁 3.String类已经重写了equals,比较时使用,同时也重写了toStri ...

  6. PowerJob 在线日志饱受好评的秘诀:小但实用的分布式日志系统

    本文适合有 Java 基础知识的人群 作者:HelloGitHub-Salieri HelloGitHub 推出的<讲解开源项目>系列. 项目地址: https://github.com/ ...

  7. Windows 下mysqldump备份1045错误解决办法

    一.我写的备份脚本如下 set d=%date:~0,4%%date:~5,2%%date:~8,2% C:\mysqldump -uroot -ptest@2018 --all-databases ...

  8. .net core 3.0 web api 重点设置,主要为了解决axios post不到参数问题

    这两天研究.net core 3.0升级,前端vue+axios 后端web api.测试过程中发现post的时候,由于提交的是json对象,后端web api获取不到数据. 今天贴了下解决过程.主要 ...

  9. RabbitMQ系列随笔——介绍及安装

    一.RabbitMQ介绍 RabbitMQ是由erlang开发的AMQP(Advanced Message Queuing Protocol)的开源实现.他是高级消息队列协议,是应用层协议的一个开放标 ...

  10. C# 压缩、解压文件夹或文件(带密码)

    今天梳理一下项目中用到的压缩.解压文件夹或文件的方法,发现因为需求不同,已经用了好几个不同组件.今天就好好整理记录下,别下次遇到需求又重头开始了. DotNetZip DotNetZip是一个开源的免 ...