优化bladefile
This commit is contained in:
parent
456aa77a69
commit
bb474c3fd5
|
|
@ -38,6 +38,7 @@ import com.smallchill.core.interfaces.IQuery;
|
|||
import com.smallchill.core.toolbox.Paras;
|
||||
import com.smallchill.core.toolbox.ajax.AjaxResult;
|
||||
import com.smallchill.core.toolbox.file.BladeFile;
|
||||
import com.smallchill.core.toolbox.file.BladeFileKit;
|
||||
import com.smallchill.core.toolbox.grid.GridManager;
|
||||
import com.smallchill.core.toolbox.kit.CharsetKit;
|
||||
import com.smallchill.core.toolbox.kit.LogKit;
|
||||
|
|
@ -176,7 +177,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public BladeFile getFile(MultipartFile file){
|
||||
return BladeFile.getFile(file);
|
||||
return BladeFileKit.getFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,7 +187,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public BladeFile getFile(MultipartFile file, String dir){
|
||||
return BladeFile.getFile(file, dir);
|
||||
return BladeFileKit.getFile(file, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,7 +199,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public BladeFile getFile(MultipartFile file, String dir, String path, String virtualPath){
|
||||
return BladeFile.getFile(file, dir, path, virtualPath);
|
||||
return BladeFileKit.getFile(file, dir, path, virtualPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -207,7 +208,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public List<BladeFile> getFiles(List<MultipartFile> files){
|
||||
return BladeFile.getFiles(files);
|
||||
return BladeFileKit.getFiles(files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -217,7 +218,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public List<BladeFile> getFiles(List<MultipartFile> files, String dir){
|
||||
return BladeFile.getFiles(files, dir);
|
||||
return BladeFileKit.getFiles(files, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -228,7 +229,7 @@ public class BladeController {
|
|||
* @return
|
||||
*/
|
||||
public List<BladeFile> getFiles(List<MultipartFile> files, String dir, String path, String virtualPath){
|
||||
return BladeFile.getFiles(files, dir, path, virtualPath);
|
||||
return BladeFileKit.getFiles(files, dir, path, virtualPath);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,17 +17,11 @@ package com.smallchill.core.toolbox.file;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.smallchill.core.constant.ConstConfig;
|
||||
import com.smallchill.core.constant.Cst;
|
||||
import com.smallchill.core.toolbox.Func;
|
||||
import com.smallchill.core.toolbox.kit.DateKit;
|
||||
import com.smallchill.core.toolbox.kit.StrKit;
|
||||
|
||||
public class BladeFile {
|
||||
/**
|
||||
|
|
@ -69,7 +63,7 @@ public class BladeFile {
|
|||
|
||||
}
|
||||
|
||||
private BladeFile(MultipartFile file, String dir) {
|
||||
public BladeFile(MultipartFile file, String dir) {
|
||||
this.dir = dir;
|
||||
this.file = file;
|
||||
this.fileName = file.getName();
|
||||
|
|
@ -78,7 +72,7 @@ public class BladeFile {
|
|||
this.uploadVirtualPath = BladeFileKit.formatUrl(Cst.me().getUploadCtxPath().replace(Cst.me().getContextPath(), "") + File.separator + dir + File.separator + DateKit.getDays() + File.separator + this.originalFileName);
|
||||
}
|
||||
|
||||
private BladeFile(MultipartFile file, String dir, String uploadPath, String uploadVirtualPath) {
|
||||
public BladeFile(MultipartFile file, String dir, String uploadPath, String uploadVirtualPath) {
|
||||
this(file, dir);
|
||||
if (null != uploadPath){
|
||||
this.uploadPath = BladeFileKit.formatUrl(uploadPath);
|
||||
|
|
@ -186,111 +180,4 @@ public class BladeFile {
|
|||
this.originalFileName = originalFileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file){
|
||||
return getFile(file, "image", null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file, String dir){
|
||||
return getFile(file, dir, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @param dir
|
||||
* @param path
|
||||
* @param virtualPath
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file, String dir, String path, String virtualPath){
|
||||
return new BladeFile(file, dir, path, virtualPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files){
|
||||
return getFiles(files, "image", null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files, String dir){
|
||||
return getFiles(files, dir, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @param path
|
||||
* @param virtualPath
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files, String dir, String path, String virtualPath){
|
||||
List<BladeFile> list = new ArrayList<>();
|
||||
for (MultipartFile file : files){
|
||||
list.add(new BladeFile(file, dir, path, virtualPath));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为虚拟路径添加配置的域名前缀
|
||||
* @param map 对象
|
||||
* @param name 路径字段名
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void addDomain(Map map, String name) {
|
||||
if (null == map) {
|
||||
return;
|
||||
}
|
||||
String url = Func.toStr(map.get(name));
|
||||
// map为引用传递, 防止每次附加到缓存
|
||||
if (url.indexOf(ConstConfig.DOMAIN) >= 0 || StrKit.isBlank(url)) {
|
||||
return;
|
||||
} else {
|
||||
url = ConstConfig.DOMAIN + url;
|
||||
map.put(name, url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为虚拟路径添加配置的域名前缀
|
||||
* @param list 对象
|
||||
* @param name 路径字段名
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void addDomain(List<Map> list, String name) {
|
||||
for (Map m : list) {
|
||||
if (null == m) {
|
||||
continue;
|
||||
}
|
||||
String url = Func.toStr(m.get(name));
|
||||
// map为引用传递, 防止每次附加到缓存
|
||||
if (url.indexOf(ConstConfig.DOMAIN) >= 0 || StrKit.isBlank(url)) {
|
||||
break;
|
||||
} else {
|
||||
url = ConstConfig.DOMAIN + url;
|
||||
m.put(name, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ import javax.imageio.stream.FileImageOutputStream;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.alibaba.druid.util.Base64;
|
||||
import com.smallchill.core.constant.ConstConfig;
|
||||
import com.smallchill.core.constant.Cst;
|
||||
import com.smallchill.core.toolbox.Func;
|
||||
import com.smallchill.core.toolbox.kit.DateKit;
|
||||
import com.smallchill.core.toolbox.kit.PathKit;
|
||||
import com.smallchill.core.toolbox.kit.StrKit;
|
||||
|
|
@ -255,5 +257,115 @@ public class BladeFileKit {
|
|||
}
|
||||
return contentPath.replace(Cst.me().getContextPath(), "");
|
||||
}
|
||||
|
||||
|
||||
/********************************BladeFile封装********************************************************/
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file){
|
||||
return getFile(file, "image", null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file, String dir){
|
||||
return getFile(file, dir, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param file
|
||||
* @param dir
|
||||
* @param path
|
||||
* @param virtualPath
|
||||
* @return
|
||||
*/
|
||||
public static BladeFile getFile(MultipartFile file, String dir, String path, String virtualPath){
|
||||
return new BladeFile(file, dir, path, virtualPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files){
|
||||
return getFiles(files, "image", null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files, String dir){
|
||||
return getFiles(files, dir, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取BladeFile封装类
|
||||
* @param files
|
||||
* @param path
|
||||
* @param virtualPath
|
||||
* @return
|
||||
*/
|
||||
public static List<BladeFile> getFiles(List<MultipartFile> files, String dir, String path, String virtualPath){
|
||||
List<BladeFile> list = new ArrayList<>();
|
||||
for (MultipartFile file : files){
|
||||
list.add(new BladeFile(file, dir, path, virtualPath));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为虚拟路径添加配置的域名前缀
|
||||
* @param map 对象
|
||||
* @param name 路径字段名
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void addDomain(Map map, String name) {
|
||||
if (null == map) {
|
||||
return;
|
||||
}
|
||||
String url = Func.toStr(map.get(name));
|
||||
// map为引用传递, 防止每次附加到缓存
|
||||
if (url.indexOf(ConstConfig.DOMAIN) >= 0 || StrKit.isBlank(url)) {
|
||||
return;
|
||||
} else {
|
||||
url = ConstConfig.DOMAIN + url;
|
||||
map.put(name, url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为虚拟路径添加配置的域名前缀
|
||||
* @param list 对象
|
||||
* @param name 路径字段名
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void addDomain(List<Map> list, String name) {
|
||||
for (Map m : list) {
|
||||
if (null == m) {
|
||||
continue;
|
||||
}
|
||||
String url = Func.toStr(m.get(name));
|
||||
// map为引用传递, 防止每次附加到缓存
|
||||
if (url.indexOf(ConstConfig.DOMAIN) >= 0 || StrKit.isBlank(url)) {
|
||||
break;
|
||||
} else {
|
||||
url = ConstConfig.DOMAIN + url;
|
||||
m.put(name, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user