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>
相关推荐
virus59455 小时前
悟空CRM mybatis-3.5.3-mapper.dtd错误解决方案
java·开发语言·mybatis
NE_STOP6 小时前
spring6-注解式开发
spring
笨蛋不要掉眼泪7 小时前
Spring Boot集成LangChain4j:与大模型对话的极速入门
java·人工智能·后端·spring·langchain
-孤存-7 小时前
MyBatis数据库配置与SQL操作全解析
数据库·mybatis
Renhao-Wan9 小时前
从零部署Spring Cloud微服务系统(Kiwi-Hub)
spring·spring cloud·微服务
csdn2015_9 小时前
MyBatis Generator 核心配置文件 generatorConfig.xml 完整配置项说明
java·mybatis
csdn2015_10 小时前
generatorConfig.xml 配置 Controller、Service 完整教程
xml·mybatis
tb_first10 小时前
万字超详细苍穹外卖学习笔记2
java·jvm·数据库·spring·tomcat·maven
1104.北光c°11 小时前
【从零开始学Redis | 第一篇】Redis常用数据结构与基础
java·开发语言·spring boot·redis·笔记·spring·nosql
Hui Baby11 小时前
Java SPI 与 Spring SPI
java·python·spring