本文整理汇总了Java中com.jfinal.core.Controller.setAttr方法的典型用法代码示例。如果您正苦于以下问题:Java Controller.setAttr方法的具体用法?Java Controller.setAttr怎么用?Java Controller.setAttr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jfinal.core.Controller
的用法示例。
在下文中一共展示了Controller.setAttr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
@Override
public void intercept(Invocation ai) {
Controller controller = ai.getController();
HttpServletRequest request = controller.getRequest();
//webRoot
controller.setAttr("_webRootPath", request.getScheme() + "://"
+ request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort())
+ request.getContextPath());
ai.invoke();
if (!ReturnKit.isJson(controller)) {
//local 数据
controller.setAttr("_localParas", request.getQueryString());
controller.setAttr("_localUri", ai.getActionKey());
}
}
示例2: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
@Override
public void intercept(ActionInvocation ai) {
Controller controller = ai.getController();
String token = controller.getPara("token");
if (StringUtils.isEmpty(token)) {
controller.renderJson(new BaseResponse(Code.ARGUMENT_ERROR, "token can not be null"));
return;
}
User user = TokenManager.getMe().validate(token);
if (user == null) {
controller.renderJson(new BaseResponse(Code.TOKEN_INVALID, "token is invalid"));
return;
}
controller.setAttr("user", user);
ai.invoke();
}
示例3: renderTo
import com.jfinal.core.Controller; //导入方法依赖的package包/类
public void renderTo(Controller controller) {
if (!hasFlashMessage(controller)) {
return;
}
HashMap<String, Object> flash = controller.getSessionAttr(FLASH_SESSION_ATTR);
if (flash == null || flash.isEmpty()) {
return;
}
for (Map.Entry<String, Object> entry : flash.entrySet()) {
controller.setAttr(entry.getKey(), entry.getValue());
}
}
示例4: handleError
import com.jfinal.core.Controller; //导入方法依赖的package包/类
@Override
protected void handleError(Controller c) {
c.keepModel(User.class);
String actionKey = getActionKey();
if (actionKey.equals("/user/save")) {
c.render("add.jsp");
} else if (actionKey.equals("/user/update"))
c.render("edit.jsp");
// 说明是有错误的
String sqlRole ="select * from role";
List<Role> roles = Role.dao.find(sqlRole);
c.setAttr("roles",roles);
c.getRequest().setAttribute("hasError", true);
}
示例5: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
public void intercept(Invocation ai) {
try {
ai.invoke();
} catch (Exception e) {
log.error("异常:", e);
Controller controller = ai.getController();
controller.setAttr("error", e.toString());
controller.render(Config.getStr("PAGES.500"));
}
}
示例6: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
public void intercept(Invocation ai) {
Controller controller = ai.getController();
// 设置公共属性
if (controller instanceof BaseController) {
BaseForm form = ((BaseController) controller).getModelByForm(BaseForm.class);
controller.setAttr("form", form);
}
ai.invoke();
}
示例7: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
public void intercept(ActionInvocation ai) {
// TODO 验证session
Controller controller = ai.getController();
ai.getController().setAttr("url",ai.getActionKey());//什么地方拦截的,登陆后返回到什么地方---touzi
if(controller.getSessionAttr("users") != null) {
ai.invoke();
}else {
controller.setAttr("msg", "需要登录才能进行操作:)");
controller.render("/_back/login/login.jsp");
}
}
示例8: intercept
import com.jfinal.core.Controller; //导入方法依赖的package包/类
@Override
public void intercept(Invocation inv) {
Controller c = inv.getController();
c.setAttr("res_root", "");
c.setAttr("_referUrl", c.getRequest().getHeader("referer"));
inv.invoke();
}
示例9: fullDevData
import com.jfinal.core.Controller; //导入方法依赖的package包/类
/**
* 方便开发环境使用,将Servlet的Request域的数据转化JSON字符串,配合dev.jsp使用,定制主题更加方便
*
* @param controller
*/
private void fullDevData(Controller controller) {
boolean dev = JFinal.me().getConstants().getDevMode();
controller.setAttr("dev", dev);
if (dev) {
Map<String, Object> attrMap = new LinkedHashMap<>();
Enumeration<String> enumerations = controller.getAttrNames();
while (enumerations.hasMoreElements()) {
String key = enumerations.nextElement();
attrMap.put(key, controller.getAttr(key));
}
controller.setAttr("requestScopeJsonString", Json.getJson().toJson(attrMap));
}
}
示例10: adminPermission
import com.jfinal.core.Controller; //导入方法依赖的package包/类
/**
* 为了规范代码,这里做了一点类是Spring的ResponseEntity的东西,及通过方法的返回值来判断是应该返回页面还会对应JSON数据
* 具体方式看 AdminRouters,这里用到了 ThreadLocal
*
* @param ai
*/
private void adminPermission(Invocation ai) {
try {
Controller controller = ai.getController();
AdminToken adminToken = adminTokenService.getAdminToken(controller.getRequest());
if (adminToken != null) {
BaseDataInitVO init = (BaseDataInitVO) ai.getController().getRequest().getAttribute("init");
Map<String, Object> webSite = init.getWebSite();
if (webSite.get("admin_dashboard_naver") == null) {
webSite.put("admin_dashboard_naver", "nav-md");
}
ai.getController().getRequest().setAttribute("webs", webSite);
try {
User user = User.dao.findById(adminToken.getUserId());
if (StringUtils.isEmpty(user.getStr("header"))) {
user.set("header", "assets/images/default-portrait.gif");
}
controller.setAttr("user", user);
TemplateHelper.fullTemplateInfo(controller);
if (!ai.getActionKey().equals("/admin/logout")) {
adminTokenService.setAdminToken(adminToken.getUserId(), adminToken.getSessionId(), controller.getRequest(), controller.getResponse());
}
ai.invoke();
// 存在消息提示
if (controller.getAttr("message") != null) {
controller.render("/admin/message.jsp");
} else {
if (!tryDoRender(ai, controller)) {
controller.render(Constants.ADMIN_NOT_FOUND_PAGE + ".jsp");
}
}
} catch (Exception e) {
LOGGER.error("", e);
exceptionHandler(ai, e);
}
} else if (ai.getActionKey().equals("/admin/login") || ai.getActionKey().equals("/api/admin/login")) {
ai.invoke();
tryDoRender(ai, controller);
} else {
blockUnLoginRequestHandler(ai);
}
} finally {
AdminTokenThreadLocal.remove();
}
}