修复字典错误

This commit is contained in:
zhouhao
2017-05-24 19:37:58 +08:00
parent b8f5d35977
commit d08ea52eca
2 changed files with 23 additions and 5 deletions

View File

@@ -45,6 +45,24 @@ public class SimpleDictionaryParser<V> implements DictionaryParser<V> {
private Map<String, String> toValueExpressions = new HashMap<>();
public SimpleDictionaryParser<V> addToTextExpression(String id, String expression) {
toTextExpressions.put(id, expression);
return this;
}
public SimpleDictionaryParser<V> addToValueExpression(String id, String expression) {
toValueExpressions.put(id, expression);
return this;
}
public void setToTextExpressions(Map<String, String> toTextExpressions) {
this.toTextExpressions = toTextExpressions;
}
public void setToValueExpressions(Map<String, String> toValueExpressions) {
this.toValueExpressions = toValueExpressions;
}
public SingleDictParser getToTextParser() {
return toTextParser;
}

View File

@@ -49,10 +49,7 @@ public class DictionaryParserTests {
"{'value':'10102','text':'红富士'}" +
",{'value':'10103','text':'青苹果'}" +
//使用表达式进行解析
",{'value':'10105','text':'其他苹果'" +
",'textExpression':'${#value}[${#context[otherApple]}]'" +
",'valueExpression':'${(#context.put(\\'otherApple\\',#pattern.split(\"[ \\\\[ \\\\]]\")[1])==null)?#value:#value}'" +
"}" +
",{'id':'10105','value':'10105','text':'其他苹果'}" +
"]}" +
",{'value':'102','text':'梨子'}]" +
"}" +
@@ -61,7 +58,10 @@ public class DictionaryParserTests {
List<SimpleDictionaryItemEntity> itemEntities = JSON.parseArray(json, SimpleDictionaryItemEntity.class);
dictionaryEntity.setItems(itemEntities);
this.parser = SimpleDictionaryParser.setDict(dictionaryEntity);
this.parser = new SimpleDictionaryParser<String>()
.addToTextExpression("10105", "${#value}[${#context[otherApple]}]")
.addToValueExpression("10105", "${(#context.put('otherApple',#pattern.split(\"[ \\[ \\]]\")[1])==null)?#value:#value}")
.setDict(dictionaryEntity);
}
//支持表达式