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>
相关推荐
N***H4868 小时前
springcloud springboot nacos版本对应
spring boot·spring·spring cloud
哈库纳玛塔塔8 小时前
放弃 MyBatis,拥抱新一代 Java 数据访问库
java·开发语言·数据库·mybatis·orm·dbvisitor
l***217810 小时前
SpringBoot Maven快速上手
spring boot·后端·maven
on the way 12310 小时前
day06-SpringDI 依赖注入
java·spring
C***115010 小时前
Spring aop 五种通知类型
java·前端·spring
M***Z21014 小时前
springboot中配置logback-spring.xml
spring boot·spring·logback
小马爱打代码17 小时前
MyBatis:插件模块详解
mybatis
xiaolyuh12317 小时前
Spring 事务核心原理 深度解析
java·数据库·spring
Codeking__18 小时前
Redis初识——什么是Redis
数据库·redis·mybatis
k***19518 小时前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring