2020-07-22 08:50

@山东小木 虽然说可以重写controller的方法,使用显示的getXXX方法获取参数,但是我更乐意在方法使用@Para注解自动注入参数,一方面是可为接口测试提供极大的便利,二是减少这类代码,让代码更加清爽

2020-07-22 08:47

@山东小木 我不是这个问题,ParaGeter是将提交的表单数据的数据值转换为对应类型,而我的问题是想在参数获取前对提交数据做预处理,这样在Controller参数注入前屏蔽掉数据特征(比如json、xml、formdata等),这样在controller处理数据时就只需关注数据内容本身。使用baseCOntroller没用,因为人家jfinal参数注入时直接使用的是request.getParaMap,也可能是我没理解木哥的意思。所以,有啥优雅的解决方案吗?

2020-07-15 19:26

@JFinal 不是这个问题,1,2,3,4,5都用了,没用哦,谢了

2020-07-15 19:25

@xialinlin 谢了,没注意到这个,我以为那是使用同一个engine

2020-07-15 16:50

@l745230 engine在plugin后启动怎么搞

2020-06-03 18:58

很久很久以前的代码了,可以参考改进一下

2020-06-03 18:56

public class ApiInterceptor implements Interceptor {
public static final String RENDER_JSON = "json";
private ActionCache action = new ActionCache();

@Override
public void intercept(Invocation invocation) {
// 这里只处理通过返回值返回客户端的数据
ApiController annotation = invocation.getController().getClass().getAnnotation(ApiController.class);
invocation.invoke();
if(null != annotation){
process(invocation , annotation);
}
}

public void process(Invocation invocation, ApiController annotation){
if(action.notReturnVoid(invocation)){
Object returnValue = invocation.getReturnValue();
String renderType = annotation.value().toLowerCase();
if (RENDER_JSON.equals(renderType)){
invocation.getController().renderJson(returnValue);
}
}
}

static class ActionCache{
HashMap mapping = new HashMap<>();

public boolean notReturnVoid(Invocation invocation){
return !isReturnVoid(invocation);
}

public boolean isReturnVoid(Invocation invocation) {
String target = invocation.getActionKey();
if (mapping.containsKey(target)) {
return mapping.get(target);
}else {
boolean isReturnVoid = invocation.getMethod().getReturnType().equals(Void.TYPE);
mapping.put(target, isReturnVoid);
return isReturnVoid;
}
}
}

}