开发者社区 问答 正文

在依赖注入的中p命名空间时的基本语法是什么啊?

在依赖注入的中p命名空间时的基本语法是什么啊?

展开
收起
游客4qo4tkog2emrs 2022-03-31 23:30:40 381 分享 版权
1 条回答
写回答
取消 提交回答
  • 语法如下:
    <?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:p="http://www.springframework.org/schema/p"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            https://www.springframework.org/schema/beans/spring-beans.xsd">
     
     
        <!--使用p命名空间来做属性注入,实际上就是使用set注入。所以它的要求和set注入一样-->
        <bean id="user" class="com.huchaun.pojo.User"
              p:id="1"
              p:name="李四"
              p:age="2"
              p:address-ref="address"
              p:hobby="下棋"/>
     
        <bean id="address" class="com.huchaun.pojo.Address"
              p:address="中国"
              p:city="四川"/>
    </beans>
     
    
    2022-03-31 23:31:19
    赞同 展开评论
问答地址: