jquery para _ filter
parent
7c35f0092f
commit
2c45f1e4f3
5
pom.xml
5
pom.xml
|
|
@ -91,5 +91,10 @@
|
||||||
<artifactId>cos</artifactId>
|
<artifactId>cos</artifactId>
|
||||||
<version>26Dec2008</version>
|
<version>26Dec2008</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.cloudowr</groupId>
|
||||||
|
<artifactId>sdk</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.cloudowr.attach;
|
package cn.cloudowr.attach;
|
||||||
|
|
||||||
|
import cn.cloudowr.sdk.JQueryParameterFilter;
|
||||||
import com.aliyun.oss.OSSClient;
|
import com.aliyun.oss.OSSClient;
|
||||||
import com.jfinal.config.*;
|
import com.jfinal.config.*;
|
||||||
import com.jfinal.template.Engine;
|
import com.jfinal.template.Engine;
|
||||||
|
|
@ -51,7 +52,7 @@ public class Config extends JFinalConfig{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configInterceptor(Interceptors me) {
|
public void configInterceptor(Interceptors me) {
|
||||||
|
me.add(new JQueryParameterFilter());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void configHandler(Handlers me) {
|
public void configHandler(Handlers me) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package cn.cloudowr.attach;
|
package cn.cloudowr.attach;
|
||||||
|
|
||||||
|
import cn.cloudowr.sdk.FastJSONUtil;
|
||||||
|
import cn.cloudowr.sdk.IdInterceptor;
|
||||||
import com.aliyun.oss.model.UploadFileRequest;
|
import com.aliyun.oss.model.UploadFileRequest;
|
||||||
import com.aliyun.oss.model.UploadFileResult;
|
import com.aliyun.oss.model.UploadFileResult;
|
||||||
import com.jfinal.aop.Before;
|
import com.jfinal.aop.Before;
|
||||||
import com.jfinal.render.ContentType;
|
|
||||||
import com.jfinal.upload.UploadFile;
|
import com.jfinal.upload.UploadFile;
|
||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
@ -15,10 +16,12 @@ import com.mongodb.client.result.UpdateResult;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.conversions.Bson;
|
import org.bson.conversions.Bson;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import sdk.FastJSONUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/17.
|
* Created by lyf66 on 2017/2/17.
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package cn.cloudowr.attach;
|
|
||||||
|
|
||||||
import com.jfinal.aop.Interceptor;
|
|
||||||
import com.jfinal.aop.Invocation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyf66 on 2017/2/16.
|
|
||||||
*/
|
|
||||||
public class IdInterceptor implements Interceptor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void intercept(Invocation inv) {
|
|
||||||
String id = inv.getController().getPara("id");
|
|
||||||
if (id != null && !id.isEmpty()) {
|
|
||||||
inv.invoke();
|
|
||||||
} else {
|
|
||||||
inv.getController().renderError(400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
package cn.cloudowr.attach;
|
|
||||||
|
|
||||||
import com.jfinal.core.JFinal;
|
|
||||||
import com.jfinal.render.Render;
|
|
||||||
import com.jfinal.render.RenderException;
|
|
||||||
import com.jfinal.render.RenderFactory;
|
|
||||||
import com.jfinal.render.RenderManager;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyf66 on 2017/2/17.
|
|
||||||
*/
|
|
||||||
public class MyFileRender extends Render {
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
private ServletContext servletContext;
|
|
||||||
|
|
||||||
public MyFileRender(File file) {
|
|
||||||
this.file = file;
|
|
||||||
this.servletContext = JFinal.me().getServletContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render() {
|
|
||||||
|
|
||||||
if (file == null || !file.isFile() || file.length() > Integer.MAX_VALUE) {
|
|
||||||
RenderManager.me().getRenderFactory().getErrorRender(404).setContext(request, response).render();
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
//源码中的代码
|
|
||||||
//response.addHeader("Content-disposition", "attachment; filename=" + file.getName());
|
|
||||||
//修改后的代码 解决中文乱码问题
|
|
||||||
try {
|
|
||||||
response.addHeader("Content-disposition",
|
|
||||||
"attachment; filename=" + new String(file.getName().getBytes("GBK"), "ISO8859-1"));
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
String contentType = servletContext.getMimeType(file.getName());
|
|
||||||
if (contentType == null) {
|
|
||||||
contentType = "application/octet-stream"; // "application/octet-stream";
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setContentType(contentType);
|
|
||||||
response.setContentLength((int)file.length());
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
|
||||||
outputStream = response.getOutputStream();
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
for (int n = -1; (n = inputStream.read(buffer)) != -1;) {
|
|
||||||
outputStream.write(buffer, 0, n);
|
|
||||||
}
|
|
||||||
outputStream.flush();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new RenderException(e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (outputStream != null) {
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
package sdk;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyf66 on 2017/2/18.
|
|
||||||
*/
|
|
||||||
public class FastJSONUtil {
|
|
||||||
private static ObjectIdSerializer serializer = new ObjectIdSerializer();
|
|
||||||
|
|
||||||
public static String bsonToJSON(Object object) {
|
|
||||||
SerializeConfig mapping = new SerializeConfig();
|
|
||||||
mapping.put(org.bson.types.ObjectId.class, serializer);
|
|
||||||
return JSON.toJSONString(object, mapping);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
package sdk;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.serializer.JSONSerializer;
|
|
||||||
import com.alibaba.fastjson.serializer.ObjectSerializer;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lisai on 17/2/9.
|
|
||||||
*/
|
|
||||||
public class ObjectIdSerializer implements ObjectSerializer {
|
|
||||||
@Override
|
|
||||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
|
||||||
if(object == null) {
|
|
||||||
serializer.getWriter().writeNull();
|
|
||||||
} else {
|
|
||||||
serializer.write(((ObjectId)object).toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue