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>
相关推荐
hzc09876543218 小时前
Spring Integration + MQTT
java·后端·spring
前路不黑暗@9 小时前
Java项目:Java脚手架项目的公共模块的实现(二)
java·开发语言·spring boot·学习·spring cloud·maven·idea
摇滚侠12 小时前
JWT 是 token 的一种格式,我的理解对吗?
java·人工智能·intellij-idea·spring ai·springaialibaba
无尽的沉默12 小时前
SpringBoot整合MyBatis-plus
spring boot·后端·mybatis
CircleMouse14 小时前
springboot项目中使用Java 8的日期时间API
java·开发语言·spring boot·后端·spring
shalou290114 小时前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring
PD我是你的真爱粉15 小时前
Redis持久化、内存管理、慢查询与发布订阅
redis·python·mybatis
我命由我1234517 小时前
Java 开发 - 如何让一个类拥有两个父类
java·服务器·开发语言·后端·java-ee·intellij-idea·intellij idea
何中应17 小时前
CentOS7安装Maven
java·运维·后端·maven