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>
相关推荐
JavaGuide18 小时前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
玹外之音21 小时前
Spring AI MCP 实战:将你的服务升级为 AI 可调用的智能工具
spring·ai编程
来一斤小鲜肉1 天前
Spring AI入门:第一个AI应用跑起来
spring·ai编程
NE_STOP1 天前
springMVC-常见视图组件与RESTFul编程风格
spring
what丶k2 天前
Spring AI 多模态开发全解析:从入门到企业级落地
后端·spring·ai编程
NE_STOP2 天前
springMVC-获取前端请求的数据与三个作用域
spring
莫寒清2 天前
Spring MVC:@PathVariable 注解详解
java·spring·mvc
-大头.2 天前
从 0 开始理解 Spring 的核心思想 —— IoC 和 DI(1)
spring
逍遥德2 天前
Maven教程.02-基础-pom.xml 使用标签大全
java·后端·maven·软件构建
莫寒清2 天前
Mybatis的插件原理
面试·mybatis