IDEA版SSM入门到实战(Maven+MyBatis+Spring+SpringMVC) -Spring依赖注入方式

第一章 Spring依赖注入方式【基于XML】

为属性赋值方式

  • 通过xxxset()方法
  • 通过构造器
  • 反射
1.1 set注入
  • 语法:<property>
1.2 构造器注入
  • 语法:<constructor-arg>
1.3 p名称空间注入

导入名称空间:xmlns:p="http://www.springframework.org/schema/p"

  • 语法:

  • 示例代码

    xml 复制代码
    <bean id="stuZhouxu" class="com.atguigu.spring.pojo.Student">
        <property name="stuId" value="102"></property>
        <property name="stuName">
            <value><![CDATA[<<zhouxu>>]]></value>
        </property>
    </bean>
    
    <bean id="stuZhiFeng" class="com.atguigu.spring.pojo.Student">
        <constructor-arg name="stuId" value="103"></constructor-arg>
        <constructor-arg name="stuName" value="zhifeng"></constructor-arg>
    </bean>
    
    <bean id="stuXiaoxi"
          class="com.atguigu.spring.pojo.Student"
          p:stuId="104"
          p:stuName="xiaoxi"></bean>
相关推荐
zjjuejin14 小时前
Maven依赖管理艺术
后端·maven
金銀銅鐵18 小时前
Spring 中的 initializeBean 方法的内部逻辑小总结
spring
zjjuejin2 天前
Maven项目的核心蓝图:POM文件
前端·maven
zjjuejin2 天前
Maven环境搭建
后端·maven
麦兜*3 天前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
麦兜*3 天前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
青衫客363 天前
Spring异步编程- 浅谈 Reactor 核心操作符
java·spring·响应式编程
Cyan_RA93 天前
SpringMVC @RequestMapping的使用演示和细节 详解
java·开发语言·后端·spring·mvc·ssm·springmvc
Hungry_Shark3 天前
IDEA版本控制管理之使用Gitee
java·gitee·intellij-idea
赛姐在努力.3 天前
《IDEA 突然“三无”?三秒找回消失的绿色启动键、主菜单和项目树!》
java·intellij-idea