日期:2014-05-20 浏览次数:20967 次
public  <forname="testForm">
            <field property="max" depends="required, maxlength">
                <arg0 key="testForm.max"/>
                <arg1 key="${var:max}" name="maxlength" resource="false" />
                <var>
                    <var-name>max</var-name>
                    <var-value>8</var-value>
                </var>
            </field>
            <field property="min" depends="required,minlength">
                <arg0 key="testForm.min"/>
                <arg1 key="${var:min}" name="minlength" resource="false" />
                <var>
                    <var-name>min</var-name>
                    <var-value>4</var-value>
                </var>
            </field>
        </form>
------解决方案--------------------
如果你是不确定要替换的内容
你可以用indexOf(),我不会正则
template.indexOf("${")
自己去找位置然后再用substring()截取或者用replace替换
我喜欢这样做法,容易看得懂
------解决方案--------------------
用MessageFormat
 MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}.");
 double[] filelimits = {0,1,2};
 String[] filepart = {"no files","one file","{0,number} files"};
 ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
 form.setFormatByArgumentIndex(0, fileform);
 Object[] testArgs = {new Long(12373), "MyDisk"};
 System.out.println(form.format(testArgs));
 // output, with different testArgs
 output: The disk "MyDisk" contains no files.
 output: The disk "MyDisk" contains one file.
 output: The disk "MyDisk" contains 1,273 files.