具有价值的网站建设,找深圳做网站的公司,常德网站建设开发公司,wordpress百度推荐P名称空间注入#xff08;用的不多#xff0c;但是也是一种方式#xff09;
目录
P名称空间注入#xff08;用的不多#xff0c;但是也是一种方式#xff09;
#xff08;1#xff09;使用P名称空间注入#xff0c;可以简化基于xml 配置方式
第一步#xff1a;添…P名称空间注入用的不多但是也是一种方式
目录
P名称空间注入用的不多但是也是一种方式
1使用P名称空间注入可以简化基于xml 配置方式
第一步添加p 名称空间在配置文件中和上面的xmlns区别就在于最后的beans和p
2进行属性注入在标签里面进行操作
第二步用p标签简化后
测试结果 1使用P名称空间注入可以简化基于xml 配置方式
首先我们先来看看初始的Spring的xml文件里面有哪些内容
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd/beans P名称空间注入的前提
修改xmlns中的约束条件
第一步添加p 名称空间在配置文件中和上面的xmlns区别就在于最后的beans和p
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance--添加p名称空间在配置文件中--xmlns:phttp://www.springframework.org/schema/pxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd/beans 2进行属性注入在bean标签里面进行操作
其次我们先来看看初始的Spring的xml文件是如何进行属性注入的
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd!--配置Book对象创建--
bean idbook classcom.lbj.spring5.Book!--使用property完成属性注入name:类里面的属性名称value:向属性注入的值--property namebname value红楼梦/property
/bean/beans 第二步用p标签简化后
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd!--配置Book对象创建--
!--使用p标签简化注入--
bean idbook classcom.lbj.spring5.Book p:bname红楼梦
/bean/beans 测试结果