• Array properties in Spring Framework


    Array properties in Spring Framework - Byte Slinger


    Array properties in Spring Framework
    Easy, simple, and apperently beyond me

    Things are so easy and intuitive with Spring that it can be frustrating when you can't figure out how to do something. I recently had a senior moment when I needed to set a String array property. I looked in several books and did a few online searches and could not find an example. I knew it was going to be easy, I just couldn't believe how easy.

    Spring automatically converts the strings in the configuration file into the Java objects required by your application. The mecanism that accomplishes this is a set of beans known as Property Editors. While it is possible to create and configure your own Property Editors, Spring comes preconfigured with Property Editors for most situations.

    What makes Spring easy to use is the support for complex types as well as primitives. List, Set, Properties, and Map objects can be ceated with Spring tags. Even better, Spring will convert Lists to Java arrays for some types.

    So, if you have Java that looks like this:


    ?
    1
    2
    3
       
    void setProperty1(String[] aStringArray){...}
    void setProperty2(List<string> aStringList){...}
    </string>

    You can configure it with XML that looks like this:
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
       
    <property name="property1">
        <list>
            <value>one</value>
            <value>two</value>
        </list>
    </property>
    <property name="property2">
        <list>
            <value>one</value>
            <value>two</value>
        </list>
    </property>
  • 相关阅读:
    ubuntu: no module named _sqlite
    mysql慢查询分析工具 pt-query-digest
    vue中的时间修饰符stop,self
    面试题 —— Ajax的基本原理总结
    es6笔记 day6-Symbol & generator
    类(class)和继承
    es6笔记 day4---模块化
    es6笔记 day3---Promise
    es6笔记 day3---对象简介语法以及对象新增
    es6笔记 day3---数组新增东西
  • 原文地址:https://www.cnblogs.com/lexus/p/2482557.html
Copyright © 2020-2023  润新知