最近看了一下jfinal
曾经用过 play 1
jfinal 对数据库的兼容性 相较 play 还是有一定的距离.
play是以model为准.不用操作数据库
jfinal是以数据库为准,基本不用操作model
jfinal的参数验证方式比较繁琐.play很优雅.jfinal controller方法不支持传参.,play这个比较灵活.不管是日期,对像还是常用数据类型都支持
jfinal render() 之前 可能需要setArg() play render()参数名即可
jfinal 每个controller都需要映射路由. play有默认的路由规则.
当然..jfinal小巧,play相较jfinal 还是有些庞大.虽然已经很精简了.
jfinal的文件上传用的是cos组件.
cos组件里头没有提供像fileupload类似的 progresslistner
所以不方便拿到文件上传的进度
.一顿搜索.没见人解决过.
小人不才,看了一下cos上传代码..暴力解决 了一下.直接修改了cos的源码
修改如下:
修改 cos的 FilePart 类:
添加了一个本地静态变量与接口
public interface Progress{
public void start();
public abstract void progress(long currentSize);
public void complate();
}
public static ThreadLocal<Progress> progresss = new ThreadLocal<Progress>();
修改了 FilePart的 write(OutputStream out)
long write(OutputStream out) throws IOException {
// decode macbinary if this was sent
if (contentType.equals("application/x-macbinary")) {
out = new MacBinaryDecoderOutputStream(out);
}
long size=0;
int read;
byte[] buf = new byte[8 * 1024];
if(progresss.get()!=null)progresss.get().start();
while((read = partInput.read(buf)) != -1) {
out.write(buf, 0, read);
size += read;
if(progresss.get()!=null)
progresss.get().progress(size);
}
if(progresss.get()!=null)progresss.get().complate();
return size;
}
controller中使用例子:
FilePart.progresss.set(new FilePart.Progress() {
public void progress(long currentSize) {
int totalsize = QuestionController.this.getRequest().getContentLength();
double csize = (double) currentSize;
double s = csize/totalsize*100;
System.out.println(String .format("%.2f",s));
}
public void start() {
}
public void complate() {
FilePart.progresss.remove();
}
});
UploadFile file = getFile();
file.getFile();
打印结果:
0.16
0.33
0.49
0.66
0.82
0.99
1.15
1.32
1.48
等...........
单应用的情况下 将 进度值存入session,前台 ajax轮存获取完成量即可