Spring c命名空間與p命名空間

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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    https://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

使用:

<!-- p命名空間注入,可以直接注入屬性的值:property-->
    <bean id="user" class="cn.aguoke.pojo.User" p:name="張三" p:age="18"/>

C命名空間

官網:

beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    https://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

使用:

<!-- c命名空間注入,通過構造器注入:construct-args-->
    <bean id="user" class="cn.aguoke.pojo.User" c:name="張三" c:age="18"/>

c命名和p命名需要導入xml約束

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章