企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**1. 一个实体类** ```java @Data public class ComplexDTO { /** 属性类型为 基本数据类型、字符串、包装类 */ private double doubleVar; private String stringVar; private String cataVar; private Long longVar; /** 属性类型为接口 */ private UserDao userDao; private UserDao userDaoTwo; /** 属性类型为一个实体类 */ private User user; /** 属性类型为集合类型 */ private String stringArray[]; private List<String> stringList; private List<Double> doubleList; private Set<String> stringSet; private Map<String, Object> objectMap; } ``` **2. IoC 中对实体类的变量赋值** ```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:utils="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <bean id="complexDto" class="learn.springioc.entity.ComplexDTO"> <property name="doubleVar" value="3.14159"/> <property name="stringVar" value="张三,你好!"/> <property name="cataVar"> <!-- 包含特殊字符的字符串写到<![CDATA[val]]>,如<、>等 --> <value><![CDATA[<<南京>>]]></value> </property> <property name="longVar" value="1000"/> <property name="userDao" ref="userDaoBean"/> <property name="userDaoTwo"> <bean id="userDaoTwo" class="learn.springioc.dao.impl.UserDaoImpl"/> </property> <property name="user" ref="userBean"/> <property name="stringArray"> <array> <value>中国</value> <value>美国</value> <value>俄罗斯</value> </array> </property> <property name="stringList"> <list> <value>中国</value> <value>美国</value> <value>俄罗斯</value> </list> </property> <property name="doubleList" ref="moneyList"/> <property name="stringSet"> <set> <value>中国</value> <value>美国</value> <value>俄罗斯</value> </set> </property> <property name="objectMap"> <map> <entry key="zhongguo" value="中国"></entry> <entry key="user" value-ref="userBean"></entry> </map> </property> </bean> <bean id="userDaoBean" class="learn.springioc.dao.impl.UserDaoImpl"/> <bean id="userBean" class="learn.springioc.entity.User"> <property name="username" value="wangwu"/> <property name="password" value="123456"/> </bean> <!-- 也有对应的 set、map --> <utils:list id="moneyList"> <value>79.45</value> <value>80.05</value> </utils:list> </beans> ```