Java Code Examples for com.jfinal.aop.Invocation#getReturnValue()
The following examples show how to use
com.jfinal.aop.Invocation#getReturnValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JbootCachePutInterceptor.java From jboot with Apache License 2.0 | 6 votes |
@Override public void intercept(Invocation inv) { //先执行,之后再保存数据 inv.invoke(); Method method = inv.getMethod(); CachePut cachePut = method.getAnnotation(CachePut.class); if (cachePut == null) { return; } Object data = inv.getReturnValue(); String unless = AnnotationUtil.get(cachePut.unless()); if (Utils.isUnless(unless, method, inv.getArgs())) { return; } Class targetClass = inv.getTarget().getClass(); String cacheName = AnnotationUtil.get(cachePut.name()); Utils.ensureCachenameAvailable(method, targetClass, cacheName); String cacheKey = Utils.buildCacheKey(AnnotationUtil.get(cachePut.key()), targetClass, method, inv.getArgs()); Utils.putDataToCache(cachePut.liveSeconds(),cacheName,cacheKey,data); }
Example 2
Source File: VisitorInterceptor.java From zrlog with Apache License 2.0 | 6 votes |
private void installPermission(Invocation ai) { String template = null; if (!ZrLogConfig.isInstalled()) { ai.invoke(); if (ai.getReturnValue() != null) { template = ai.getReturnValue(); } } else { ai.getController().getRequest().setAttribute("errorMsg", ((Map) ai.getController().getRequest().getAttribute("_res")).get("installed")); } if (template == null) { template = "/install/forbidden"; } ai.getController().setAttr("currentViewName", template.substring("/install/".length())); ai.getController().render(new FreeMarkerRender(template + ".ftl")); }
Example 3
Source File: VisitorInterceptor.java From zrlog with Apache License 2.0 | 5 votes |
/** * 查询出来的文章数据存放在request域里面,通过判断Key,选择对应需要渲染的模板文件 * * @param ai */ private void visitorPermission(Invocation ai) { ai.invoke(); String templateName = ai.getReturnValue(); if (templateName == null) { return; } GlobalResourceHandler.printUserTime("Template before"); String templatePath = TemplateHelper.fullTemplateInfo(ai.getController(), true); GlobalResourceHandler.printUserTime("Template after"); TemplateVO templateVO = new TemplateService().getTemplateVO(JFinal.me().getContextPath(), new File(PathKit.getWebRootPath() + templatePath)); String ext = ZrLogUtil.getViewExt(templateVO.getViewType()); if (ai.getController().getAttr("log") != null) { ai.getController().setAttr("pageLevel", 1); } else if (ai.getController().getAttr("data") != null) { if ("/".equals(ai.getActionKey()) && new File(PathKit.getWebRootPath() + templatePath + "/" + templateName + ext).exists()) { ai.getController().setAttr("pageLevel", 2); } else { templateName = "page"; ai.getController().setAttr("pageLevel", 1); } } else { ai.getController().setAttr("pageLevel", 2); } fullDevData(ai.getController()); String viewPath = templatePath + "/" + templateName + ext; if (ext.equals(".ftl")) { BlogFrontendFreeMarkerRender render = new BlogFrontendFreeMarkerRender(viewPath); render.setContext(ai.getController().getRequest(), ai.getController().getResponse()); ai.getController().render(render); } else { ai.getController().render(viewPath); } }
Example 4
Source File: AdminInterceptor.java From zrlog with Apache License 2.0 | 5 votes |
/** * 尝试通过Controller的放回值来进行数据的渲染 * * @param ai * @param controller * @return true 表示已经渲染数据了,false 表示并未按照约定编写,及没有进行渲染 */ private boolean tryDoRender(Invocation ai, Controller controller) { Object returnValue = ai.getReturnValue(); if (ai.getMethod().getAnnotation(RefreshCache.class) != null) { cacheService.refreshInitDataCache(GlobalResourceHandler.CACHE_HTML_PATH, controller, true); if (JFinal.me().getConstants().getDevMode()) { LOGGER.info("{} trigger refresh cache", controller.getRequest().getRequestURI()); } } boolean rendered = false; if (returnValue != null) { if (ai.getActionKey().startsWith("/api/admin")) { controller.renderJson((Object) ai.getReturnValue()); rendered = true; } else if (ai.getActionKey().startsWith("/admin") && returnValue instanceof String) { //返回值,约定:admin 开头的不写模板类型,其他要写全 if (!returnValue.toString().endsWith(".jsp") && returnValue.toString().startsWith("/admin")) { String templatePath = returnValue.toString() + ".ftl"; if (AdminInterceptor.class.getResourceAsStream(Constants.FTL_VIEW_PATH + templatePath) != null) { controller.render(new FreeMarkerRender(templatePath)); rendered = true; } else { rendered = false; } } else { controller.render(returnValue.toString()); rendered = true; } } } else { rendered = true; } return rendered; }
Example 5
Source File: JbootCacheInterceptor.java From jboot with Apache License 2.0 | 4 votes |
@Override public void intercept(Invocation inv) { Method method = inv.getMethod(); Cacheable cacheable = method.getAnnotation(Cacheable.class); if (cacheable == null) { inv.invoke(); return; } String unlessString = AnnotationUtil.get(cacheable.unless()); if (Utils.isUnless(unlessString, method, inv.getArgs())) { inv.invoke(); return; } Class targetClass = inv.getTarget().getClass(); String cacheName = AnnotationUtil.get(cacheable.name()); Utils.ensureCachenameAvailable(method, targetClass, cacheName); String cacheKey = Utils.buildCacheKey(AnnotationUtil.get(cacheable.key()), targetClass, method, inv.getArgs()); Object data = AopCache.get(cacheName, cacheKey); if (data != null) { if (NULL_VALUE.equals(data)) { inv.setReturnValue(null); } else if (cacheable.returnCopyEnable()) { inv.setReturnValue(getCopyObject(inv, data)); } else { inv.setReturnValue(data); } } else { inv.invoke(); data = inv.getReturnValue(); if (data != null) { Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, data); //当启用返回 copy 值的时候,返回的内容应该是一个进行copy之后的值 if (cacheable.returnCopyEnable()) { inv.setReturnValue(getCopyObject(inv, data)); } } else if (cacheable.nullCacheEnable()) { Utils.putDataToCache(cacheable.liveSeconds(), cacheName, cacheKey, NULL_VALUE); } } }