博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring学习笔记(二)
阅读量:7193 次
发布时间:2019-06-29

本文共 1942 字,大约阅读时间需要 6 分钟。

hot3.png

注入参数详解

1.       直接注入值

<bean id=”car” class=”com.smart.attr.Car”>

           <property name=”speed”>

                    <value>2000</value>

           </property>

</bean>

也可以将value作为property属性使用,当value值包涵xml标签或其他可能引起xml异常的符号时,应该使用<![CDATE[String]]>,把其中内容当字符串解析

2.       应用其他Bean

<bean id=”person” class=”com.smart.person”>

         <property name=”car”>

                    <ref bean=”car”/>

        </property>

</bean>

<bean id=”car” class=”com.smart.attr.Car”/>

<ref >属性有bean/local/parent

3.       集合类型属性

重要包括List、Set、Map、Properties

(1)       List

<bean id=”person” class=”com.smart.person”>

             <list>

                       <value>读书</value>

                       <value>看报</value>

                       <value>游泳</value>

             </list>

</bean>

可以直接注入字符串,也可以通过<ref>注入其他Bean;Set类似

(2)       Map

<bean id=”person” class=”com.smart.person”>

    <property name=”name”>

                              <map>

                                       <entry>

                                                <key><value>key</value></key>

                                                <value>value</value>

                                        </entry>

                            </map>

    </property>

</bean>

 

(3)       Properties

Properties可以看作Map的特例,Map的键值可以使任何类型的对象,而Properties键值只能是字符串

 

<bean id=”person” class=”com.smart.person”>

                    <property name=”name”>

                             <props>

                                       <prop key=”key”>value</prop>

                             </props>

                    </property>

</bean>

4.       通过util命名空间配置集合类型的Bean以及p简化配置

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:p="http://www.springframework.org/schema/p"

       xmlns:util="http://www.springframework.org/schema/util"

       xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://www.springframework.org/schema/util

       http://www.springframework.org/schema/util/spring-util-3.1.xsd>

…..

           <util:list id=”favorite” list-class=”java.util.ArrayList”>

                    <value>value</value>

           </util:list>

           <util:set id=”” set-class=””>

                    <value></value>

           </util:list>

           <util:map id=”” map-class=””>

                    <entry key=”” value=”” />

           </util:map>

           <! --list 和set支持 value-type map支持key-type和value-type 限定值类型 -- >

……

           <! –p命名空间简化配置 -- >

           <bean id=”car” class=””

                p:brand=””

                p:maxSpeed=””

                p:price=”” />

                   

           <bean id=”person” class=””

                p:car-ref=”car”/>

</bean>

转载于:https://my.oschina.net/u/1413049/blog/192783

你可能感兴趣的文章
支付宝担保交易接口
查看>>
深入浅出三剑客之sed必杀技一例
查看>>
django sitemap设置为https
查看>>
我的友情链接
查看>>
微信内部浏览器打开网页时提示外部浏览器打开遮罩升级版
查看>>
Go语言类型的本质
查看>>
界面主窗体,子窗体的InitializeComponent(构造函数)、Load事件执行顺序
查看>>
java导入导出Excel数据的要点记录
查看>>
汇编2——完整的例子集合
查看>>
TP缓存设计方案解析
查看>>
APIO2010 特别行动队
查看>>
Javascript语言精粹之Array常用方法分析
查看>>
leetcode 304. Range Sum Query 2D - Immutable
查看>>
Session704: Core ML 3 Framework 观后小结
查看>>
springmvc freemarker 页面访问静态类的解决方法
查看>>
[理] virsh 命令
查看>>
Python进阶【第十篇】模块(上)
查看>>
Oracle 官方文档 结构说明(教你如何快速从官方文档中获取需要的知识)
查看>>
jQuery
查看>>
mysql 增删改查最基本用法小结
查看>>