cn.tom.mvc.handler.DefaultController Maven / Gradle / Ivy
package cn.tom.mvc.handler;
import java.io.IOException;
import java.lang.reflect.Method;
import javax.servlet.ServletException;
import cn.tom.mvc.core.ControllerInvoke;
import cn.tom.mvc.core.RequestContext;
import cn.tom.mvc.interceptor.ActionInvocation;
import cn.tom.mvc.view.View;
import cn.tom.mvc.view.ViewFactory;
public final class DefaultController implements Controller {
@Override
public void enter(ActionInvocation actionInvocation) throws ServletException, IOException {
long a = System.currentTimeMillis();
String module = actionInvocation.getParaMap().get("module");
RequestContext context = actionInvocation.getRequestContext();
try {
ControllerInvoke controllerInvoke = new ControllerInvoke(actionInvocation);
controllerInvoke.paserFieldAnotation();
Object obj = controllerInvoke.parserControllerMethod();
String page = (String) obj;
if (page != null && !page.isEmpty()) {
/*模板解析*/
View view = ViewFactory.getView();
if(view!=null){
view.render(context.getRealPage(page));
}else{
context.forward(page, true);
}
}
long last = (System.currentTimeMillis()-a);
String msg = module+"- " +last +" - "+getModel(actionInvocation.getMethod())+" - "+context.getIpAddr();
logger.info(msg);
} catch(Exception e){
logger.error(e.getMessage(), e);
}finally {
actionInvocation.recycle();
actionInvocation = null;
}
}
private String getModel(Method me){
return me.getDeclaringClass() +"." + me.getName();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy