mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 14:15:50 +08:00
修复字典错误
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
//支持表达式
|
||||
|
||||
Reference in New Issue
Block a user