341 | | |
342 | | |
343 | | |
344 | | |
| 341 | == 資料集合 == |
| 342 | |
| 343 | 對於像 '''陣列、java.util.List、java.util.Set、java.util.Map''' 等'''集合物件''',在注入前必須填充入一些物件至集合中,然後再將集合物件注入至所需的Bean中, |
| 344 | |
| 345 | * SomeBean : |
| 346 | |
| 347 | {{{ |
| 348 | #!java |
| 349 | public class SomeBean { |
| 350 | private String[] someStrArray; |
| 351 | private SomeObj[] someObjArray; |
| 352 | private List someList; |
| 353 | private Map someMap; |
| 354 | .... |
| 355 | |
| 356 | } |
| 357 | }}} |
| 358 | |
| 359 | * B.xml :陣列,List => <list> ; Map => <map> |
| 360 | |
| 361 | {{{ |
| 362 | #!xml |
| 363 | <beans> |
| 364 | <bean id="someBean" class="onlyfun.caterpillar.SomeBean"> |
| 365 | <property name="someArray"> |
| 366 | <list> |
| 367 | <value>Hello!Justin!</value> |
| 368 | <value>Hello!Momor!</value> |
| 369 | <value>Hello!Bush!</value> |
| 370 | </list> |
| 371 | </property> |
| 372 | <property name="someObjArray"> |
| 373 | <list> |
| 374 | <ref bean="someObj1"/> |
| 375 | <ref bean="someObj2"/> |
| 376 | </list> |
| 377 | </property> |
| 378 | <property name="someList"> |
| 379 | <list> |
| 380 | <value>Hello!Justin!</value> |
| 381 | <ref bean="someObj1"/> |
| 382 | <ref bean="someObj2"/> |
| 383 | </list> |
| 384 | </property> |
| 385 | <property name="someMap"> |
| 386 | <map> |
| 387 | <entry key="somekey1"> |
| 388 | <ref bean="someObj1"/> |
| 389 | </entry> |
| 390 | <entry key="somekey2"> |
| 391 | <value>Hello!Justin!</value> |
| 392 | </entry> |
| 393 | </map> |
| 394 | </property> |
| 395 | </bean> |
| 396 | </beans> |
| 397 | }}} |
| 398 | |
| 399 | 上面的Bean定義檔是個綜合示範,陣列與List物件都是用<list>標籤來設定,而Map物件使用<map>標籤設定,並需要一個key值設定。 |
| 400 | |
| 401 | * Set => <set> : |
| 402 | |
| 403 | {{{ |
| 404 | #!xml |
| 405 | <set> |
| 406 | <value>a set element</value> |
| 407 | <ref bean="otherBean"/> |
| 408 | <ref bean="anotherBean"/> |
| 409 | </set> |
| 410 | }}} |