activiti 사용자 정의 함수 해석 주엘 표현식
public String getStringByELAndFormData(String el, Map formData) throws Exception {
ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext();
for (Object k : formData.keySet()) {
if (formData.get(k) != null) {
context.setVariable(k.toString(),
factory.createValueExpression(formData.get(k), formData.get(k).getClass()));
}
}
ValueExpression e = factory.createValueExpression(context, el, String.class);
return (String) e.getValue(context);
}
이런 방법은 문제가 없지만 변수 집행에만 국한된다.하지만 방법류 호출을 늘리면 문제가 있습니다!
현재 주리 변수 표현식이 있습니다. 표현식은 ${fn test.getJiebaoPost (",", ")}입니다.이 표현식은 다음과 같은 종류를 호출해야 한다
public class FunctionOrgService {
public String getJiebaoPost(String id,String nodeFlag,String exParams){
return "82301111111";
}
}
원래 해석한 코드에 문제가 생겼다. 왜냐하면 그는 이 함수를 식별할 방법이 없기 때문이다.
해결 방법은 다음과 같다.
Map map=new HashMap();
map.put("fn_test", new FunctionOrgService());
processEngineConfiguration.setBeans(map);
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.activiti.engine.delegate.VariableScope;
import org.activiti.engine.impl.persistence.entity.VariableInstance;
public class TestVariableScope implements VariableScope{
private Map variables=new HashMap();
public TestVariableScope(Map variables){
this.variables=variables;
}
@Override
public Map getVariables() {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstances() {
/*// TODO Auto-generated method stub
Map variableInstanceMap=new HashMap();
System.out.println(" Map.entrySet key value");
for (Map.Entry entry : variables.entrySet()) {
VariableInstanceEntity variableInstance=VariableInstanceEntity.create( entry.getKey(), type, entry.getValue())
}*/
return null;
}
@Override
public Map getVariables(Collection variableNames) {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstances(Collection variableNames) {
// TODO Auto-generated method stub
return null;
}
@Override
public Map getVariables(Collection variableNames, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstances(Collection variableNames,
boolean fetchAllVariables) {
// TODO Auto-generated method stub
return null;
}
@Override
public Map getVariablesLocal() {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstancesLocal() {
// TODO Auto-generated method stub
return null;
}
@Override
public Map getVariablesLocal(Collection variableNames) {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstancesLocal(Collection variableNames) {
// TODO Auto-generated method stub
return null;
}
@Override
public Map getVariablesLocal(Collection variableNames, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return variables;
}
@Override
public Map getVariableInstancesLocal(Collection variableNames,
boolean fetchAllVariables) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getVariable(String variableName) {
// TODO Auto-generated method stub
return variables.get(variableName);
}
@Override
public VariableInstance getVariableInstance(String variableName) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getVariable(String variableName, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return this.getVariable(variableName);
}
@Override
public VariableInstance getVariableInstance(String variableName, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getVariableLocal(String variableName) {
// TODO Auto-generated method stub
return this.getVariable(variableName);
}
@Override
public VariableInstance getVariableInstanceLocal(String variableName) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getVariableLocal(String variableName, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return this.getVariable(variableName);
}
@Override
public VariableInstance getVariableInstanceLocal(String variableName, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return null;
}
@Override
public T getVariable(String variableName, Class variableClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public T getVariableLocal(String variableName, Class variableClass) {
// TODO Auto-generated method stub
return null;
}
@Override
public Set getVariableNames() {
// TODO Auto-generated method stub
return null;
}
@Override
public Set getVariableNamesLocal() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setVariable(String variableName, Object value) {
// TODO Auto-generated method stub
variables.put(variableName,value);
}
@Override
public void setVariable(String variableName, Object value, boolean fetchAllVariables) {
// TODO Auto-generated method stub
this.setVariable(variableName, value);
}
@Override
public Object setVariableLocal(String variableName, Object value) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object setVariableLocal(String variableName, Object value, boolean fetchAllVariables) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setVariables(Map variables) {
// TODO Auto-generated method stub
this.variables=(Map) variables;
}
@Override
public void setVariablesLocal(Map variables) {
// TODO Auto-generated method stub
this.variables=(Map) variables;
}
@Override
public boolean hasVariables() {
// TODO Auto-generated method stub
return variables.size()>0;
}
@Override
public boolean hasVariablesLocal() {
// TODO Auto-generated method stub
return variables.size()>0;
}
@Override
public boolean hasVariable(String variableName) {
// TODO Auto-generated method stub
return variables.containsKey(variableName);
}
@Override
public boolean hasVariableLocal(String variableName) {
// TODO Auto-generated method stub
return variables.containsKey(variableName);
}
@Override
public void createVariableLocal(String variableName, Object value) {
// TODO Auto-generated method stub
}
@Override
public void removeVariable(String variableName) {
// TODO Auto-generated method stub
}
@Override
public void removeVariableLocal(String variableName) {
// TODO Auto-generated method stub
}
@Override
public void removeVariables(Collection variableNames) {
// TODO Auto-generated method stub
}
@Override
public void removeVariablesLocal(Collection variableNames) {
// TODO Auto-generated method stub
}
@Override
public void removeVariables() {
// TODO Auto-generated method stub
}
@Override
public void removeVariablesLocal() {
// TODO Auto-generated method stub
}
}
상기 코드는 맵 하나만 전송하면 되며, 많은 방법은 실현할 필요가 없다.
3. 주엘의 표현식 실행하기
public class JuelExpressonCommand implements Command
이 표현식은 OK!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.