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>
相关推荐
山北雨夜漫步3 分钟前
点评day02 商户缓存
缓存·mybatis
亓才孓26 分钟前
[SpringIOC]NoUniqueBeanDefinitionException
java·spring
hrhcode10 小时前
【Netty】五.ByteBuf内存管理深度剖析
java·后端·spring·springboot·netty
宋小黑12 小时前
MyBatis Generator GUI 下载安装教程 可视化MyBatis代码生成
mybatis
前路不黑暗@12 小时前
Java项目:Java脚手架项目的通用组件的封装(六)
java·开发语言·spring
树码小子13 小时前
Mybatis(13)MyBatis Generator(xml生成器)& Mybatis-Plus初识
xml·mybatis
无心水15 小时前
5、微服务快速启航:基于Pig与BladeX构建高可用分布式系统实战
服务器·分布式·后端·spring·微服务·云原生·架构
求知摆渡15 小时前
Spring AI 多模型对话 Demo 实战:OpenAI/Ollama 一套接口、Redis 会话记忆、SSE 流式输出、AOP 日志打点
java·spring
前路不黑暗@17 小时前
Java项目:Java脚手架项目的地图服务(十)
java·数据库·spring boot·笔记·学习·spring cloud·maven
hrhcode19 小时前
【Netty】三.ChannelPipeline与ChannelHandler责任链深度解析
java·后端·spring·springboot·netty