Spring6(三)P命名空间C命名空间UTILS类的的set注入(3.7)

文章介绍了Spring框架中P命名空间作为属性注入的简化写法,C命名空间对应构造器注入,而UTIL命名空间用于配置工具类,如数据库连接参数。通过添加特定的XML命名空间和schemaLocation,可以在配置文件中使用这些简化的写法。
摘要由CSDN通过智能技术生成

util

P命名空间实际上是set注入的另一种写法(我也不知道为什么要开发这么多种写法???为了方便反而更乱了)

C命名空间实际上是构造器注入的另一种写法

UTIL实际上是工具类的另一种写法

三者都要改变头文件

首先是P命名空间

首先要引入可以写P命名空间的约束

<?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">



</beans>

首先复制一行

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

然后改写为

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

此时已经可以用p命名来

此时的语法是

<bean id="aaa"    class="com.chenchen.dao.juese"  p:name="学习"  p:skill="大家"></bean>

当然也可引用p-ref注入别的引用类型

c命名空间就不记录了。

util命名空间如下

首先还是要引入

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

然后在复制一行

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

将其中所有的beans改为util

即为

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

整体是是这样的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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.xsd">

然后就可以在配置文件中写<util>标签

util主要是配置工具类 比如 连接数据库所需要的url useranme等

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值