Spring之级联属性

Easter79
• 阅读 551

新建XML文件

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
    <bean id="car" class="com.auguigu.spring.beans.Car">
        <constructor-arg value="Audi" type="java.lang.String"></constructor-arg>
        <constructor-arg value="Shanghai" type="java.lang.String"></constructor-arg>
        <constructor-arg value="30000" type="int"></constructor-arg>
    </bean>    
    <bean id="person" class="com.auguigu.spring.beans.Person">
        <constructor-arg type="java.lang.String" value="Tom"></constructor-arg>
        <constructor-arg type="java.lang.String" value="11"></constructor-arg>
        <constructor-arg ref="car"></constructor-arg>
        <property name="car.price" value="1111"></property>
    </bean>
</beans>

所以,当一个类引用另一个类时也可以通过在Bean中分别为引用的类注入值

<property name="car.price" value="1111"></property>结束语:

为级联属性赋值,属性需要先初始化才可以为级联属性赋值,否则会有异常,和Struts2不同

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Stella981 Stella981
2年前
AndroidStudio封装SDK的那些事
<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael
Stella981 Stella981
2年前
Spring MVC 配置文件dispatcher
1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:mvc\"http://www.springframework.org/schema/mvc"4.xml
Easter79 Easter79
2年前
Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
背景:学习切面,测试前置通知功能,xml配置如下<?xmlversion"1.0"encoding"UTF8"?<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http:/
Wesley13 Wesley13
2年前
Spring中hibernateTemplate的使用
1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:xsi\"http://www.w3.org/2001/XMLSchemainstance"xmlns:con
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Redis在SSM框架的使用(三)
Spring整合springdataredis1、springredis.xml<?xmlversion"1.0"encoding"UTF8"?<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Wesley13 Wesley13
2年前
ActiveMQ的spring配置文件
从官网copy出来,做了部分修改:1<?xmlversion"1.0"encoding"UTF8"?2<beansxmlns"http://www.springframework.org/schema/beans"3xmlns:xsi"http://www.w3.org/2
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k