本文整理汇总了Java中com.jfinal.core.Controller类的典型用法代码示例。如果您正苦于以下问题:Java Controller类的具体用法?Java Controller怎么用?Java Controller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Controller类属于com.jfinal.core包,在下文中一共展示了Controller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: renderError
import com.jfinal.core.Controller; //导入依赖的package包/类
private void renderError(Controller controller, String form, String message, String errorRedirect) {
message = StringUtils.isBlank(message) ? "数据不能为空" : message;
if (StringUtils.isNotBlank(errorRedirect)) {
if (controller instanceof JbootController) {
JbootController c = (JbootController) controller;
c.setFlashMap(Ret.fail("message", message).set("code", DEFAULT_ERROR_CODE).set("form", form));
}
controller.redirect(errorRedirect);
return;
}
//如果ajax请求,返回一个错误数据。
if (RequestUtils.isAjaxRequest(controller.getRequest())) {
controller.renderJson(Ret.fail("message", message).set("code", DEFAULT_ERROR_CODE).set("form", form));
return;
}
controller.renderError(404);
}
示例3: createActionKey
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 参考ActionMapping中的实现。
*
* @param controllerClass
* @param method
* @param controllerKey
* @return
*/
private String createActionKey(Class<? extends Controller> controllerClass,
Method method, String controllerKey) {
String methodName = method.getName();
String actionKey;
ActionKey ak = method.getAnnotation(ActionKey.class);
if (ak != null) {
actionKey = ak.value().trim();
if ("".equals(actionKey))
throw new IllegalArgumentException(controllerClass.getName() + "." + methodName + "(): The argument of ActionKey can not be blank.");
if (!actionKey.startsWith(SLASH))
actionKey = SLASH + actionKey;
} else if (methodName.equals("index")) {
actionKey = controllerKey;
} else {
actionKey = controllerKey.equals(SLASH) ? SLASH + methodName : controllerKey + SLASH + methodName;
}
return actionKey;
}
示例4: configRoute
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 路由配置
*/
@SuppressWarnings("unchecked")
public void configRoute(Routes routes) {
List<Class<Controller>> controllerClassList = ClassScaner.scanSubClass(Controller.class);
if (controllerClassList != null) {
for (Class<?> clazz : controllerClassList) {
UrlMapping urlMapping = clazz.getAnnotation(UrlMapping.class);
if (null != urlMapping && StringUtils.isNotBlank(urlMapping.url())) {
if (StrKit.notBlank(urlMapping.viewPath())) {
routes.add(urlMapping.url(), (Class<? extends Controller>) clazz, urlMapping.viewPath());
} else {
routes.add(urlMapping.url(), (Class<? extends Controller>) clazz);
}
}
}
}
}
示例5: createActionKey
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 构建actionkey,参考ActionMapping中的实现。
*
* @param controllerClass
* @param method
* @param controllerKey
* @return
*/
private String createActionKey(Class<? extends Controller> controllerClass, Method method, String controllerKey) {
String methodName = method.getName();
String actionKey = "";
ActionKey ak = method.getAnnotation(ActionKey.class);
if (ak != null) {
actionKey = ak.value().trim();
if ("".equals(actionKey))
throw new IllegalArgumentException(controllerClass.getName() + "." + methodName + "(): The argument of ActionKey can not be blank.");
if (!actionKey.startsWith(SLASH))
actionKey = SLASH + actionKey;
} else if (methodName.equals("index")) {
actionKey = controllerKey;
} else {
actionKey = controllerKey.equals(SLASH) ? SLASH + methodName : controllerKey + SLASH + methodName;
}
return actionKey;
}
示例6: logFromConfig
import com.jfinal.core.Controller; //导入依赖的package包/类
private void logFromConfig(Controller c, LogConfig log) {
SysLog sysLog = new SysLog();
sysLog.ip = ServletKit.getIp(c.getRequest());
sysLog.user = logProcesser.getUsername(c);
Map<String, String[]> parameterMap = c.getRequest().getParameterMap();
Set<Entry<String, String[]>> entrySet = parameterMap.entrySet();
Map<String, String> paraMap = Maps.newHashMap();
for (Entry<String, String[]> entry : entrySet) {
String key = entry.getKey();
String value = entry.getValue()[0];
String result = log.params.get(key);
if (StrKit.isBlank(result))
continue;
paraMap.put(result, value);
}
sysLog.message = logProcesser.formatMessage(log.title, paraMap);
logProcesser.process(sysLog);
}
示例7: createActionKey
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 构建actionkey,参考ActionMapping中的实现。
*
* @param controllerClass
* @param method
* @param controllerKey
* @return
*/
private String createActionKey(Class<? extends Controller> controllerClass,
Method method, String controllerKey) {
String methodName = method.getName();
String actionKey = "";
ActionKey ak = method.getAnnotation(ActionKey.class);
if (ak != null) {
actionKey = ak.value().trim();
if ("".equals(actionKey))
throw new IllegalArgumentException(controllerClass.getName() + "." + methodName + "(): The argument of ActionKey can not be blank.");
if (!actionKey.startsWith(SLASH))
actionKey = SLASH + actionKey;
}
else if (methodName.equals("index")) {
actionKey = controllerKey;
}
else {
actionKey = controllerKey.equals(SLASH) ? SLASH + methodName : controllerKey + SLASH + methodName;
}
return actionKey;
}
示例8: intercept
import com.jfinal.core.Controller; //导入依赖的package包/类
public void intercept(Invocation ai) {
Controller controller = ai.getController();
Field[] fields = controller.getClass().getDeclaredFields();
for (Field field : fields) {
Object bean = null;
if (field.isAnnotationPresent(Inject.BY_NAME.class))
bean = ctx.getBean(field.getName());
else if (field.isAnnotationPresent(Inject.BY_TYPE.class))
bean = ctx.getBean(field.getType());
else
continue ;
try {
if (bean != null) {
field.setAccessible(true);
field.set(controller, bean);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
ai.invoke();
}
示例9: 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();
}
示例10: checkSignature
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 检测签名
*/
private boolean checkSignature(Controller controller) {
String signature = controller.getPara("signature");
String timestamp = controller.getPara("timestamp");
String nonce = controller.getPara("nonce");
if (StrKit.isBlank(signature) || StrKit.isBlank(timestamp) || StrKit.isBlank(nonce)) {
controller.renderText("check signature failure");
return false;
}
if (SignatureCheckKit.me.checkSignature(signature, timestamp, nonce)) {
return true;
}
else {
log.error("check signature failure: " +
" signature = " + controller.getPara("signature") +
" timestamp = " + controller.getPara("timestamp") +
" nonce = " + controller.getPara("nonce"));
return false;
}
}
示例11: intercept
import com.jfinal.core.Controller; //导入依赖的package包/类
public void intercept(ActionInvocation ai) {
// 如果是服务器配置请求,则配置服务器并返回
Controller controller = ai.getController();
HttpServletRequest request= controller.getRequest();
String url=request.getRequestURL().toString()+"?" + request.getQueryString();
log.info("request url:"+url);
if (isConfigServerRequest(controller)) {
configServer(controller);
return ;
}
// 签名检测
if (checkSignature(controller)) {
ai.invoke();
}
}
示例12: configServer
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 配置开发者中心微信服务器所需的 url 与 token
* @return true 为config server 请求,false 正式消息交互请求
*/
public void configServer(Controller c) {
String msg_signature = c.getPara("msg_signature");
String timestamp = c.getPara("timestamp");
String nonce = c.getPara("nonce");
String echostr = c.getPara("echostr");
//非加密验证
boolean isOk = SignatureCheckKit.me.checkSignature(msg_signature, timestamp, nonce,echostr);
if (isOk){
WxCryptUtil pc = getWxCryptUtil();
echostr= pc.decrypt(echostr);
log.info("验证成功,解密后的echostr:"+echostr);
c.renderText(echostr);
}
else
log.error("验证失败:configServer!");
}
示例13: checkSignature
import com.jfinal.core.Controller; //导入依赖的package包/类
/**
* 检测签名
*/
private boolean checkSignature(Controller controller) {
String signature = controller.getPara("signature");
String timestamp = controller.getPara("timestamp");
String nonce = controller.getPara("nonce");
if (StrKit.isBlank(signature) || StrKit.isBlank(timestamp) || StrKit.isBlank(nonce)) {
controller.renderText("check signature failure");
return false;
}
if (SignatureCheckKit.me.checkSignature(signature, timestamp, nonce)) {
return true;
}
else {
logger.error("check signature failure: " +
" signature = " + controller.getPara("signature") +
" timestamp = " + controller.getPara("timestamp") +
" nonce = " + controller.getPara("nonce"));
return false;
}
}
示例14: logFromConfig
import com.jfinal.core.Controller; //导入依赖的package包/类
private void logFromConfig(Controller c, LogConfig log) {
SysLog sysLog = new SysLog();
final HttpServletRequest request = c.getRequest();
final String remoteIP = Requests.remoteIP(request);
sysLog.setIp(remoteIP);
sysLog.setUser(logProcesser.getUsername(c));
Map<String, String[]> parameterMap = request.getParameterMap();
Set<Entry<String, String[]>> entrySet = parameterMap.entrySet();
Map<String, String> paraMap = Maps.newHashMap();
for (Entry<String, String[]> entry : entrySet) {
String key = entry.getKey();
String value = entry.getValue()[0];
String result = log.params.get(key);
if (StrKit.isBlank(result))
continue;
paraMap.put(result, value);
}
final String message = logProcesser.formatMessage(log.title, paraMap);
sysLog.setMessage(message);
sysLog.setTitle(log.getTitle());
logProcesser.process(sysLog);
}
示例15: config
import com.jfinal.core.Controller; //导入依赖的package包/类
@Override
public void config() {
final Set<Class<? extends Controller>> controllerList = ClassPathScanning.scan(Controller.class);
if (CollectionUtils.isNotEmpty(controllerList)) {
ControllerBind controllerBind;
for (Class<? extends Controller> controller : controllerList) {
controllerBind = controller.getAnnotation(ControllerBind.class);
if (controllerBind == null) {
final String controllerKey = controllerKey(controller);
if (Strings.isNullOrEmpty(controllerKey)) {
logger.warn("控制器类{},路由生成失败!", controller.getName());
continue;
}
this.add(controllerKey, controller);
} else if (StrKit.isBlank(controllerBind.viewPath())) {
this.add(controllerBind.value(), controller);
} else {
this.add(controllerBind.value(), controller, controllerBind.viewPath());
}
}
}
}