Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this:</p> <pre><code>&lt;beans:bean id="someClass" class="com.you.SomeClass" &gt; &lt;beans:property name="myIntArray"&gt; &lt;beans:list&gt; &lt;beans:list&gt; &lt;beans:value&gt;1&lt;/beans:value&gt; &lt;beans:value&gt;2&lt;/beans:value&gt; &lt;beans:value&gt;3&lt;/beans:value&gt; &lt;/beans:list&gt; &lt;beans:list&gt; &lt;beans:value&gt;4&lt;/beans:value&gt; &lt;beans:value&gt;5&lt;/beans:value&gt; &lt;beans:value&gt;6&lt;/beans:value&gt; &lt;/beans:list&gt; &lt;beans:list&gt; &lt;beans:value&gt;7&lt;/beans:value&gt; &lt;beans:value&gt;8&lt;/beans:value&gt; &lt;beans:value&gt;9&lt;/beans:value&gt; &lt;/beans:list&gt; &lt;/beans:list&gt; &lt;/beans:property&gt; &lt;/beans:bean&gt; </code></pre> <p>Or:</p> <pre><code>&lt;beans:bean id="someClass" class="com.you.SomeClass" &gt; &lt;beans:property name="myIntArray"&gt; &lt;beans:array&gt; &lt;beans:array&gt; &lt;beans:value&gt;1&lt;/beans:value&gt; &lt;beans:value&gt;2&lt;/beans:value&gt; &lt;beans:value&gt;3&lt;/beans:value&gt; &lt;/beans:array&gt; &lt;beans:array&gt; &lt;beans:value&gt;4&lt;/beans:value&gt; &lt;beans:value&gt;5&lt;/beans:value&gt; &lt;beans:value&gt;6&lt;/beans:value&gt; &lt;/beans:array&gt; &lt;beans:array&gt; &lt;beans:value&gt;7&lt;/beans:value&gt; &lt;beans:value&gt;8&lt;/beans:value&gt; &lt;beans:value&gt;9&lt;/beans:value&gt; &lt;/beans:array&gt; &lt;/beans:array&gt; &lt;/beans:property&gt; &lt;/beans:bean&gt; </code></pre> <p><strong>UPDATE: Supply your own converter</strong></p> <p>Another way would be to use <a href="http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/convert/converter/Converter.html" rel="nofollow">Converter</a>s. Here is an example implementation:</p> <pre><code>public class IntArrayConverter implements Converter&lt;String, int[][]&gt; { @Override public int[][] convert(String source) { if(isBlank(source)) { return new int[0][0]; } String[] subArraysStrs = source.split(":"); int[][] result = new int[subArraysStrs.length][]; for(int i = 0; i &lt; subArraysStrs.length; i++) { String subArrayStr = trim(subArraysStrs[i]); if(isBlank(subArrayStr)) { throw new IllegalArgumentException(); } String[] subArrayElementStrs = subArrayStr.split(","); int[] subArray = new int[subArrayElementStrs.length]; for(int j = 0; j &lt; subArray.length; j++) { String elementStr = trim(subArrayElementStrs[j]); subArray[j] = Integer.parseInt(elementStr); } result[i] = subArray; } return result; } } </code></pre> <p>Now, tell spring that it can use this converter by declaring the following in your configuration:</p> <pre><code>&lt;bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"&gt; &lt;property name="converters"&gt; &lt;list&gt; &lt;bean class="com.example.IntArrayConverter" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>and then:</p> <pre><code>&lt;bean class="com.you.SomeClass"&gt; &lt;property name="myIntArray" value="1,2,3:4,5,6:7,8,9"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre> <p>My <a href="http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/convert/converter/Converter.html" rel="nofollow">Converter</a> is implemented to be used without the curly braces around each sub-array for simplicity. That is, instead of </p> <pre><code>&lt;property name="myIntArray" value="{1,2,3},{4,5,6},{7,8,9}"&gt;&lt;/property&gt; </code></pre> <p>I am going with </p> <pre><code>&lt;property name="myIntArray" value="1,2,3:4,5,6:7,8,9"&gt;&lt;/property&gt; </code></pre> <p>If you want, you can modify the code to interpret any kind of string format. For more details about <a href="http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/convert/converter/Converter.html" rel="nofollow">Converter</a>s, you can look <a href="http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/validation.html#core-convert" rel="nofollow">here</a>.</p> <p><strong>Note</strong>: The registered <code>ConversionService</code> will be availabel to your entire app. That is, it will be used whenever there is a need to convert a <code>String</code> into an <code>int[][]</code>. Also, even though you provide only one converter, all the default converters are registered anyway, so you won't lose their benefits.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload