mirror of
https://gitee.com/EMF/solon-manager.git
synced 2025-12-06 16:58:28 +08:00
mod: 文件上传,系统类型,动态磁盘保存位置
This commit is contained in:
parent
9e3bcd298c
commit
273def4069
@ -9,6 +9,7 @@ import org.noear.solon.web.staticfiles.StaticConfig;
|
||||
import org.noear.solon.web.staticfiles.StaticMappings;
|
||||
import org.noear.solon.web.staticfiles.repository.ClassPathStaticRepository;
|
||||
import org.noear.solon.web.staticfiles.repository.FileStaticRepository;
|
||||
import vip.fuck.sm.common.utils.FileConfig;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
@ -24,7 +25,7 @@ public class SolonManagerApplication {
|
||||
Solon.start(SolonManagerApplication.class, args, app->{
|
||||
//例:或者:增加全局处理(用过滤器模式)
|
||||
app.filter(-1, new CrossFilter().allowedOrigins("*")); //加-1 优先级更高
|
||||
String filePath = app.cfg().getProperty("file.path" );
|
||||
String filePath = FileConfig.getFilePath();
|
||||
StaticMappings.add("/files/", new FileStaticRepository(filePath));
|
||||
StaticMappings.add("/static/", new ClassPathStaticRepository(StaticConfig.RES_STATIC_LOCATION));
|
||||
});
|
||||
|
||||
16
src/main/java/vip/fuck/sm/common/utils/FileConfig.java
Normal file
16
src/main/java/vip/fuck/sm/common/utils/FileConfig.java
Normal file
@ -0,0 +1,16 @@
|
||||
package vip.fuck.sm.common.utils;
|
||||
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
public class FileConfig {
|
||||
public static String getFilePath(){
|
||||
String key ;
|
||||
if(SystemUtil.getOsInfo().isWindows()){
|
||||
key = "file.path-win";
|
||||
}else{
|
||||
key = "file.path-linux";
|
||||
}
|
||||
return Solon.cfg().get(key,"/file-path");
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import vip.fuck.sm.common.exception.BusinessException;
|
||||
import vip.fuck.sm.common.utils.DateUtils;
|
||||
import vip.fuck.sm.common.utils.FileConfig;
|
||||
import vip.fuck.sm.entity.SysFilesEntity;
|
||||
import vip.fuck.sm.mapper.SysFilesMapper;
|
||||
import vip.fuck.sm.service.SysFilesService;
|
||||
@ -31,8 +32,9 @@ import java.util.UUID;
|
||||
public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEntity> implements SysFilesService {
|
||||
|
||||
|
||||
@Inject("${file.path}")
|
||||
private String filePath;
|
||||
|
||||
|
||||
|
||||
|
||||
@Inject("${file.contextPath}")
|
||||
private String fileContextPath;
|
||||
@ -44,6 +46,7 @@ public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEnt
|
||||
public String saveFile(UploadedFile file, HttpRequest request) {
|
||||
//存储文件夹
|
||||
String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN);
|
||||
String filePath = FileConfig.getFilePath();
|
||||
String newPath = filePath + File.separator + createTime + File.separator;
|
||||
File uploadDirectory = new File(newPath);
|
||||
if (uploadDirectory.exists()) {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
server.port: 8080
|
||||
server.contextPath: '/manager'
|
||||
solon.env: 'dev'
|
||||
server:
|
||||
port: 8080
|
||||
contextPath: '/manager'
|
||||
|
||||
#使用代码生成模块时 指定要生成的表存在于哪种数据库,可选值有【mysql、oracle、sqlServer】
|
||||
project:
|
||||
database: mysql
|
||||
|
||||
solon:
|
||||
env: 'dev'
|
||||
app:
|
||||
name: 'solon-manager'
|
||||
group: 'vip.fuck'
|
||||
@ -29,6 +34,8 @@ redis:
|
||||
password: ""
|
||||
maxTotal: 200 #默认为 200,可不配
|
||||
serializer: 'org.noear.redisx.utils.SerializerJson'
|
||||
|
||||
|
||||
mybatis.master:
|
||||
typeAliases: #支持包名 或 类名(大写开头 或 *)//支持 ** 或 * 占位符
|
||||
- "vip.fuck.sm.entity"
|
||||
@ -36,7 +43,7 @@ mybatis.master:
|
||||
- "vip.fuck.sm.entity.handler"
|
||||
mappers: #支持包名 或 类名(大写开头 或 *)或 xml(.xml结尾)//支持 ** 或 * 占位符
|
||||
- "vip.fuck.sm.mapper.*" #这个表达式同上效果
|
||||
- "classpath:mapper/${project.database}/**/*.xml,classpath:mapper/*.xml"
|
||||
- "classpath:mapper/${project.database}/**/*.xml"
|
||||
- "classpath:mapper/*.xml"
|
||||
configuration: #扩展配置(要与 MybatisConfiguration 类的属性一一对应)
|
||||
cacheEnabled: false
|
||||
@ -76,13 +83,11 @@ knife4j.setting.enableOpenApi: false
|
||||
knife4j.setting.enableSwaggerModels: false
|
||||
knife4j.setting.enableFooter: false
|
||||
|
||||
#使用代码生成模块时 指定要生成的表存在于哪种数据库,可选值有【mysql、oracle、sqlServer】
|
||||
project:
|
||||
database: mysql
|
||||
|
||||
|
||||
file:
|
||||
schema: 'http'
|
||||
contextPath: 'localhost:${server.port}/${server.contextPath}/'
|
||||
#文件上传目录 绝对路径 末尾不需要加 /
|
||||
path: 'D:/files' #windows
|
||||
#path: /data/files #linux
|
||||
path-win: 'D:/files' #windows
|
||||
path-linux: '/data/files' #linux
|
||||
Loading…
x
Reference in New Issue
Block a user