Skip to content

Commit

Permalink
修改demo
Browse files Browse the repository at this point in the history
  • Loading branch information
longshu committed Jun 24, 2017
1 parent 32717d2 commit 7c3bd68
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
14 changes: 10 additions & 4 deletions demo/src/main/java/longshu/easycontroller/demo/DemoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,34 @@
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.io.Serializable;
import java.sql.Connection;

/**
* DemoConfig
*
* @author LongShu 2017/06/20
*/
public class DemoConfig extends ActionConfig implements Serializable {
public class DemoConfig extends ActionConfig {
private static final long serialVersionUID = 1L;

@Override
public void configConstant(Constants me) {
me.setDevMode(true);
prop = loadPropertyFile("demo.properties");
me.setDevMode(getPropToBoolean("devMode", false));
me.setViewType(ViewType.JSP);
me.setViewExtension(".jsp");

// 指定json实现
me.setDefaultJson(new FastJson());

me.setErrorView(404, "/WEB-INF/jsps/error/404.jsp");
me.setErrorView(500, "/WEB-INF/jsps/error/500.jsp");

// 文件上传配置
me.addAllowUploadFileType(getProp("allowFileType"));
// 文件下载缓存配置
me.setFileCacheSize(getPropToInt("fileCacheSize", 80));
me.setMaxFileCachetSize(getPropToInt("maxFileCachetSize", 2 << 10));// 2M
}

@Override
Expand All @@ -55,7 +61,7 @@ public void configModule(BeanFactory me) {
public void configInterceptor(Interceptors me) {
// 全局拦截器
me.addGlobalInterceptor(GlobalInterceptor.class);

// 给某个控制器指定拦截器
me.addActionInterceptor(TestController.class, TestInterceptor.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class TestInterceptor implements Interceptor {
public void intercept(ActionInvocation invocation) {
log.info("TestInterceptor:{} 执行前", invocation.getActionKey());
invocation.invoke();
log.info("TestInterceptor:{} 执行后", invocation.getActionKey());
}

}
13 changes: 13 additions & 0 deletions demo/src/main/resources/demo.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

devMode=true

# 允许上传的文件类型
allowFileType=.jpg; .jpeg; .png; .txt; .doc; .docx; .zip; .rar; .mp4; .avi; .wav; .txt

# 文件缓存数量
fileCacheSize=50

# 最大的缓存文件大小 2M
maxFileCachetSize=2048

# 其他配置...
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean handle(String target, HttpServletRequest request, HttpServletResp
try {
invocation.invoke();
returnValue = invocation.getReturnValue();
logger.debug("returnValue:[{}]", returnValue);
logger.debug("returnValue: [{}]", returnValue);
} catch (ActionException e) {
logger.warn(e.getMessage(), e);
ViewManager.me().getViewFactory().getErrorView(500).render(request, response);
Expand All @@ -95,7 +95,7 @@ public boolean handle(String target, HttpServletRequest request, HttpServletResp

// resolveView
View view = viewResolver.resolveView(action, returnValue);
logger.debug("view:{}", view);
logger.debug("view: [{}]", view);

// ContextPath
if ((view instanceof AbstractUrlView) || (view instanceof ForwardView)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @author LongShu 2017/05/11
*/
public class FileUtil {

/**
* The Unix separator character.
*/
Expand All @@ -22,39 +23,6 @@ public class FileUtil {
*/
public static final char WINDOWS_SEPARATOR = '\\';

/**
* 返回如: 2017/01/
*/
public static String buildYearMonth() {
Date date = new Date();
return DateUtil.toStr(date, "yyyy/MM/");
}

/**
* 按照日期打乱
*
* @param basePath 文件存储路径
* @return 如 savePath/2017/01
*/
public static File getSavePath(File basePath) {
File dir = new File(basePath, buildYearMonth());
if (!dir.exists()) {//如果文件夹不存在就创建
mkdirs(dir);
}
return dir;
}

/**
* 参数重载一个方法,由于保存是按照绝对路径的
* 并且我们按照日期打乱
*
* @param basePath
* @return
*/
public static String getSavePath(String basePath) {
return getSavePath(new File(basePath)).getAbsolutePath();
}

/**
* 获取有后缀的文件名称
* <pre>
Expand Down

0 comments on commit 7c3bd68

Please sign in to comment.