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>
相关推荐
Wang's Blog4 小时前
Java框架快速入门: Spring Security+OAuth2之数据库和实体类的RBAC改造
java·数据库·spring
sunshine22 girl6 小时前
Idea中如何搜索
java·ide·intellij-idea
猫吻鱼6 小时前
【AI 01】【Spring AI 基础使用】
java·spring·spring ai
Wang's Blog9 小时前
Java框架快速入门: Spring Security+OAuth2之JWT核心概念与实战
java·spring·log4j
Wang's Blog10 小时前
Java框架快速入门: Spring Security+OAuth2之核心角色与授权流程
java·spring·github
Wang's Blog10 小时前
Java框架快速入门: Spring Security+OAuth2之RBAC与角色分层实践
java·网络·spring
干到60岁退休的码农10 小时前
15.创建获取用户接口与JWT认证器
java·spring boot·mybatis
golang学习记12 小时前
IDEA 2026.3 EAP新特性:自动识别Spring Boot的新 profile 了
java·spring boot·intellij-idea
liangsheng_g14 小时前
Spring事务传播行为分派与挂起恢复源码实战
数据库·sql·spring
麻瓜code14 小时前
【Agent】从 0 手写智能体框架:ReAct + ToolCall 分层设计
人工智能·spring