本文整理汇总了Java中com.jfinal.core.JFinal类的典型用法代码示例。如果您正苦于以下问题:Java JFinal类的具体用法?Java JFinal怎么用?Java JFinal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JFinal类属于com.jfinal.core包,在下文中一共展示了JFinal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readString
import com.jfinal.core.JFinal; //导入依赖的package包/类
public static String readString(File file) {
ByteArrayOutputStream baos = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int len = 0; (len = fis.read(buffer)) > 0;) {
baos.write(buffer, 0, len);
}
return new String(baos.toByteArray(), JFinal.me().getConstants().getEncoding());
} catch (Exception e) {
} finally {
close(fis, baos);
}
return null;
}
示例2: readString
import com.jfinal.core.JFinal; //导入依赖的package包/类
public static String readString(File file) {
ByteArrayOutputStream baos = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int len = 0; (len = fis.read(buffer)) > 0;) {
baos.write(buffer, 0, len);
}
return new String(baos.toByteArray(),JFinal.me().getConstants().getEncoding());
} catch (Exception e) {
} finally {
close(fis, baos);
}
return null;
}
示例3: handle
import com.jfinal.core.JFinal; //导入依赖的package包/类
@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
if (!target.startsWith("/api")) {
this.nextHandler.handle(target, request, response, isHandled);
return;
}
if (JFinal.me().getAction(target, new String[1]) == null) {
isHandled[0] = true;
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
RenderFactory.me().getJsonRender(new BaseResponse(Code.NOT_FOUND, "resource is not found")).setContext(request, response).render();
} else {
this.nextHandler.handle(target, request, response, isHandled);
}
}
示例4: renderMsg
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 在接收到微信服务器的消息后响应消息
*/
public void renderMsg(SentMsg outMsg) {
String outMsgXml = MsgSentBuilder.build(outMsg);
// 开发模式向控制台输出即将发送的 OutMsg 消息的 xml 内容
if (JFinal.me().getConstants().getDevMode()) {
System.out.println("发送消息:");
System.out.println(outMsgXml);
System.out.println("--------------------------------------------------------------------------------");
}
// 是否需要加密消息
WcBase base = WcCache.getWxBase("");
if (base.isEncrypt()) {
outMsgXml = MsgEncryptUtil.encrypt(base, outMsgXml, getPara("timestamp"), getPara("nonce"));
}
renderText(outMsgXml, "text/xml");
}
示例5: intercept
import com.jfinal.core.JFinal; //导入依赖的package包/类
@Override
public void intercept(Invocation invocation) {
if (invocation.getController() instanceof BaseController) {
BaseController baseController = (BaseController) invocation.getController();
String ipStr = baseController.getStrValueByKey("blackList");
if (ipStr != null) {
Set<String> ipSet = new HashSet<>(Arrays.asList(ipStr.split(",")));
String requestIP = WebTools.getRealIp(baseController.getRequest());
if (ipSet.contains(requestIP)) {
baseController.render(JFinal.me().getConstants().getErrorView(403));
} else {
invocation.invoke();
}
} else {
invocation.invoke();
}
} else {
invocation.invoke();
}
}
示例6: tryDoRender
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 尝试通过Controller的放回值来进行数据的渲染
*
* @param ai
* @param controller
* @return true 表示已经渲染数据了,false 表示并未按照约定编写,及没有进行渲染
*/
private boolean tryDoRender(Invocation ai, Controller controller) {
Object returnValue = ai.getReturnValue();
boolean rendered = false;
if (returnValue != null) {
if (ai.getActionKey().startsWith("/api/admin")) {
controller.renderJson(ai.getReturnValue());
rendered = true;
} else if (ai.getActionKey().startsWith("/admin") && returnValue instanceof String) {
if (JFinal.me().getConstants().getViewType() == ViewType.JSP) {
String templatePath = returnValue.toString() + ".jsp";
if (new File(PathKit.getWebRootPath() + templatePath).exists()) {
controller.render(templatePath);
rendered = true;
} else {
rendered = false;
}
}
}
} else {
rendered = true;
}
return rendered;
}
示例7: index
import com.jfinal.core.JFinal; //导入依赖的package包/类
public String index() {
if (AdminTokenThreadLocal.getUser() != null) {
Map<String, Object> commentMap = Comment.dao.noRead(1, 5);
if (commentMap.get("rows") != null) {
List<Comment> rows = (List<Comment>) commentMap.get("rows");
for (Comment comment : rows) {
comment.put("userComment", ParseUtil.autoDigest(comment.get("userComment").toString(), 15));
}
}
JFinal.me().getServletContext().setAttribute("comments", commentMap);
JFinal.me().getServletContext().setAttribute("commCount", Comment.dao.getCommentCount());
JFinal.me().getServletContext().setAttribute("toDayCommCount", Comment.dao.getToDayCommentCount());
JFinal.me().getServletContext().setAttribute("clickCount", Log.dao.sumAllClick());
JFinal.me().getServletContext().setAttribute("lastVersion", new UpgradeController().lastVersion());
if (getPara(0) == null || getRequest().getRequestURI().endsWith("admin/") || "login".equals(getPara(0))) {
redirect("/admin/index");
return null;
} else {
return "/admin/" + getPara(0);
}
} else {
return "/admin/login";
}
}
示例8: testDbConn
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 检查数据库是否可以正常连接使用,无法连接时给出相应的提示
*/
public void testDbConn() {
Map<String, String> dbConn = new HashMap<>();
dbConn.put("jdbcUrl", "jdbc:mysql://" + getPara("dbhost") + ":"
+ getPara("port") + "/" + getPara("dbname")
+ "?&characterEncoding=UTF-8");
dbConn.put("user", getPara("dbuser"));
dbConn.put("password", getPara("dbpwd"));
dbConn.put("driverClass", "com.mysql.jdbc.Driver");
JFinal.me().getServletContext().setAttribute("dbConn", dbConn);
if (new InstallService(PathKit.getWebRootPath() + "/WEB-INF", dbConn).testDbConn()) {
render("/install/message.jsp");
} else {
setAttr("errorMsg", I18NUtil.getStringFromRes("connectDbError", getRequest()));
index();
}
}
示例9: installZrlog
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 数据库检查通过后,根据填写信息,执行数据表,表数据的初始化
*/
public void installZrlog() {
String home = getRequest().getScheme() + "://" + getRequest().getHeader("host") + getRequest().getContextPath() + "/";
Map<String, String> dbConn = (Map<String, String>) JFinal.me().getServletContext().getAttribute("dbConn");
Map<String, String> configMsg = new HashMap<>();
configMsg.put("title", getPara("title"));
configMsg.put("second_title", getPara("second_title"));
configMsg.put("username", getPara("username"));
configMsg.put("password", getPara("password"));
configMsg.put("email", getPara("email"));
configMsg.put("home", home);
if (new InstallService(PathKit.getWebRootPath() + "/WEB-INF", dbConn, configMsg).install()) {
render("/install/success.jsp");
ZrlogConfig config = (ZrlogConfig) JFinal.me().getServletContext().getAttribute("config");
//通知启动插件,配置库连接等操作
config.installFinish();
}
}
示例10: runBlogPlugin
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 运行Zrlog的插件,当WEB-INF/plugins/这里目录下面不存在plugin-core.jar时,会通过网络请求下载最新的plugin核心服务,也可以通过
* 这种方式进行插件的及时更新。
* plugin-core也是一个java进程,通过调用系统命令的命令进行启动的。
*
* @param dbPropertiesPath
* @param pluginJvmArgs
*/
private void runBlogPlugin(final String dbPropertiesPath, final String pluginJvmArgs) {
//这里使用独立的线程进行启动,主要是为了防止插件服务出问题后,影响整体,同时是避免启动过慢的问题。
new Thread() {
@Override
public void run() {
PluginConfig.stopPluginCore();
//加载 zrlog 提供的插件
File pluginCoreFile = new File(PathKit.getWebRootPath() + "/WEB-INF/plugins/plugin-core.jar");
if (!pluginCoreFile.exists()) {
pluginCoreFile.getParentFile().mkdirs();
String filePath = pluginCoreFile.getParentFile().toString();
try {
LOGGER.info("plugin-core.jar not exists will download from " + PLUGIN_CORE_DOWNLOAD_URL);
HttpUtil.getInstance().sendGetRequest(PLUGIN_CORE_DOWNLOAD_URL + "?_=" + System.currentTimeMillis(), new HashMap<String, String[]>(), new HttpFileHandle(filePath), new HashMap<String, String>());
} catch (IOException e) {
LOGGER.warn("download plugin core error", e);
}
}
int port = PluginConfig.pluginServerStart(pluginCoreFile, dbPropertiesPath, pluginJvmArgs, PathKit.getWebRootPath(), BlogBuildInfoUtil.getVersion());
JFinal.me().getServletContext().setAttribute("pluginServerPort", port);
JFinal.me().getServletContext().setAttribute("pluginServer", "http://localhost:" + port);
}
}.start();
}
示例11: afterJFinalStart
import com.jfinal.core.JFinal; //导入依赖的package包/类
/**
* 设置系统参数到Servlet的Context用于后台管理的主页面的展示,读取Zrlog的版本信息等。
* 为了处理由于数据库表的更新,导致系统无法正常使用的情况,通过执行/WEB-INF/update-sql/目录下面的*.sql文件来变更数据库的表格式,
* 来达到系统无需手动执行数据库脚本文件。
*/
@Override
public void afterJFinalStart() {
super.afterJFinalStart();
systemProp.setProperty("zrlog.runtime.path", JFinal.me().getServletContext().getRealPath("/"));
systemProp.setProperty("server.info", JFinal.me().getServletContext().getServerInfo());
JFinal.me().getServletContext().setAttribute("system", systemProp);
systemProperties.put("version", BlogBuildInfoUtil.getVersion());
systemProperties.put("buildId", BlogBuildInfoUtil.getBuildId());
systemProperties.put("buildTime", new SimpleDateFormat("yyyy-MM-dd").format(BlogBuildInfoUtil.getTime()));
systemProperties.put("runMode", BlogBuildInfoUtil.getRunMode());
JFinal.me().getServletContext().setAttribute("zrlog", systemProperties);
JFinal.me().getServletContext().setAttribute("config", this);
if (!isInstalled()) {
LOGGER.warn("Not found lock file(" + PathKit.getWebRootPath() + "/WEB-INF/install.lock), Please visit the http://yourHostName:port" + JFinal.me().getContextPath() + "/install installation");
} else {
//检查数据文件是否需要更新
String sqlVersion = WebSite.dao.getValueByName(com.zrlog.common.Constants.ZRLOG_SQL_VERSION_KEY);
Integer updatedVersion = ZrlogUtil.doUpgrade(sqlVersion, PathKit.getWebRootPath() + "/WEB-INF/update-sql", dbProperties.getProperty("jdbcUrl"), dbProperties.getProperty("user"),
dbProperties.getProperty("password"), dbProperties.getProperty("driverClass"));
if (updatedVersion > 0) {
WebSite.dao.updateByKV(com.zrlog.common.Constants.ZRLOG_SQL_VERSION_KEY, updatedVersion + "");
}
}
}
示例12: genHeaderMapByRequest
import com.jfinal.core.JFinal; //导入依赖的package包/类
public static Map<String, String> genHeaderMapByRequest(HttpServletRequest request) {
Map<String, String> map = new HashMap<>();
AdminToken adminToken = AdminTokenThreadLocal.getUser();
if (adminToken != null) {
User user = User.dao.findById(adminToken.getUserId());
map.put("LoginUserName", user.get("userName").toString());
map.put("LoginUserId", adminToken.getUserId() + "");
}
map.put("IsLogin", (adminToken != null) + "");
map.put("Blog-Version", ((Map) JFinal.me().getServletContext().getAttribute("zrlog")).get("version").toString());
if (request != null) {
String fullUrl = getFullUrl(request);
if (request.getQueryString() != null) {
fullUrl = fullUrl + "?" + request.getQueryString();
}
map.put("Cookie", request.getHeader("Cookie"));
map.put("AccessUrl", WebTools.getRealScheme(request) + "://" + request.getHeader("Host") + request.getContextPath());
if (request.getHeader("Content-Type") != null) {
map.put("Content-Type", request.getHeader("Content-Type"));
}
map.put("Full-Url", fullUrl);
}
return map;
}
示例13: render
import com.jfinal.core.JFinal; //导入依赖的package包/类
@Override
public void render() {
JetEngine engine = JetWebEngineLoader.getJetEngine();
if (engine == null) {
JetWebEngineLoader.setServletContext(JFinal.me().getServletContext());
}
String charsetEncoding = engine.getConfig().getOutputEncoding();
response.setCharacterEncoding(charsetEncoding);
if (response.getContentType() == null) {
response.setContentType("text/html; charset=" + charsetEncoding);
}
JetContext context = new JetWebContext(request, response);
JetTemplate template = engine.getTemplate(view);
try {
template.render(context, response.getOutputStream());
} catch (IOException e) {
throw ExceptionUtils.uncheck(e);
}
}
示例14: main
import com.jfinal.core.JFinal; //导入依赖的package包/类
public static void main(String[] args) {
JFinal.start("src/main/webapp", 9090, "/walle", 1);
}
示例15: handle
import com.jfinal.core.JFinal; //导入依赖的package包/类
@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
if (!webConfig.isActionCacheEnable()) {
next.handle(target, request, response, isHandled);
return;
}
Action action = JFinal.me().getAction(target, urlPara);
if (action == null) {
next.handle(target, request, response, isHandled);
return;
}
ActionCacheClear actionClear = action.getMethod().getAnnotation(ActionCacheClear.class);
if (actionClear != null) {
clearActionCache(action, actionClear);
next.handle(target, request, response, isHandled);
return;
}
EnableActionCache actionCache = getActionCache(action);
if (actionCache == null) {
next.handle(target, request, response, isHandled);
return;
}
try {
exec(target, request, response, isHandled, action, actionCache);
} finally {
ActionCacheContext.release();
}
}