Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
U
UEditor-OSS
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
毛洋
UEditor-OSS
Commits
a3beed5c
提交
a3beed5c
authored
7月 19, 2025
作者:
杨占军
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
oss变本地
上级
b1118bbc
流水线
#32274
已失败 于阶段
in 4 seconds
变更
10
流水线
1
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
550 行增加
和
58 行删除
+550
-58
pom.xml
pom.xml
+24
-1
MyWebAppConfigurer.java
src/main/java/com/example/MyWebAppConfigurer.java
+16
-0
StorageManager.java
...java/com/example/baidu/ueditor/upload/StorageManager.java
+48
-9
UEditorController.java
src/main/java/com/example/controller/UEditorController.java
+11
-32
FileConstants.java
...n/java/com/example/util/uploadLocalost/FileConstants.java
+9
-0
FileLocalUtils.java
.../java/com/example/util/uploadLocalost/FileLocalUtils.java
+219
-0
JsonUtil.java
src/main/java/com/example/util/uploadLocalost/JsonUtil.java
+121
-0
MultipartFileToFileLocalUse.java
...mple/util/uploadLocalost/MultipartFileToFileLocalUse.java
+55
-0
UploadResultDto.java
...java/com/example/util/uploadLocalost/UploadResultDto.java
+26
-0
application.properties
src/main/resources/application.properties
+21
-16
没有找到文件。
pom.xml
浏览文件 @
a3beed5c
...
@@ -94,13 +94,36 @@
...
@@ -94,13 +94,36 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
<version>
28.2-jre
</version>
<version>
28.2-jre
</version>
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<!-- HuTool -->
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.14
</version>
</dependency>
<!-- fast json 依赖-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.47
</version>
</dependency>
<dependency>
<groupId>
de.javakaffee
</groupId>
<artifactId>
kryo-serializers
</artifactId>
<version>
0.45
</version>
</dependency>
<dependency>
<groupId>
com.esotericsoftware
</groupId>
<artifactId>
kryo
</artifactId>
<version>
4.0.2
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/example/MyWebAppConfigurer.java
浏览文件 @
a3beed5c
package
com
.
example
;
package
com
.
example
;
import
com.example.util.uploadLocalost.FileConstants
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
/**
/**
...
@@ -19,4 +22,17 @@ public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {
...
@@ -19,4 +22,17 @@ public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
);
registry
.
addMapping
(
"/**"
);
}
}
@Value
(
"${file.path}"
)
private
String
filePath
=
"D:/"
;
/**
* 静态资源映射,使Java可以访问E文件下下面的东西,映射路径为/core/**
*
* @param registry
*/
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/"
+
FileConstants
.
FILE_URL_NAME
+
"/**"
).
addResourceLocations
(
"file:"
+
filePath
+
FileConstants
.
FILE_URL_NAME
+
"/"
);
}
}
}
\ No newline at end of file
src/main/java/com/example/baidu/ueditor/upload/StorageManager.java
浏览文件 @
a3beed5c
...
@@ -5,17 +5,17 @@ import com.example.baidu.ueditor.define.AppInfo;
...
@@ -5,17 +5,17 @@ import com.example.baidu.ueditor.define.AppInfo;
import
com.example.baidu.ueditor.define.BaseState
;
import
com.example.baidu.ueditor.define.BaseState
;
import
com.example.baidu.ueditor.define.State
;
import
com.example.baidu.ueditor.define.State
;
import
java.io.BufferedInputStream
;
import
java.io.*
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
com.example.util.AliyunOSSUtil
;
import
com.example.util.AliyunOSSUtil
;
import
com.example.util.uploadLocalost.FileLocalUtils
;
import
com.example.util.uploadLocalost.UploadResultDto
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
StorageManager
{
public
class
StorageManager
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
StorageManager
.
class
);
public
static
final
int
BUFFER_SIZE
=
8192
;
public
static
final
int
BUFFER_SIZE
=
8192
;
public
StorageManager
()
{
public
StorageManager
()
{
...
@@ -108,13 +108,31 @@ public class StorageManager {
...
@@ -108,13 +108,31 @@ public class StorageManager {
return
new
File
(
tmpDir
,
tmpFileName
);
return
new
File
(
tmpDir
,
tmpFileName
);
}
}
/**
* oss图片存储
*/
// private static State saveTmpFile(File tmpFile, String path) {
// State state;
// AliyunOSSUtil aliyunOSSUtil= (com.example.util.AliyunOSSUtil) SpringContextUtils.getBean("aliyunOSSUtil");
// String upolad = aliyunOSSUtil.upolad(tmpFile, path);
// state = new BaseState(true);
// state.putInfo("size", tmpFile.length());
// state.putInfo("url", upolad);
// return state;
// }
/**
* 本地图片存储
*/
private
static
State
saveTmpFile
(
File
tmpFile
,
String
path
)
{
private
static
State
saveTmpFile
(
File
tmpFile
,
String
path
)
{
State
state
;
State
state
;
AliyunOSSUtil
aliyunOSSUtil
=
(
com
.
example
.
util
.
AliyunOSSUtil
)
SpringContextUtils
.
getBean
(
"aliyunOSSUtil"
);
String
extension
=
path
.
split
(
"\\."
)[
1
];
String
upolad
=
aliyunOSSUtil
.
upolad
(
tmpFile
,
path
);
FileLocalUtils
fileLocalUtils
=
(
FileLocalUtils
)
SpringContextUtils
.
getBean
(
"fileLocalUtils"
);
UploadResultDto
uploadResultDto
=
fileLocalUtils
.
uploadFile
(
fileToByteArray
(
tmpFile
),
"."
+
extension
);
state
=
new
BaseState
(
true
);
state
=
new
BaseState
(
true
);
state
.
putInfo
(
"size"
,
tmpFile
.
length
());
state
.
putInfo
(
"size"
,
tmpFile
.
length
());
state
.
putInfo
(
"url"
,
upolad
);
state
.
putInfo
(
"url"
,
uploadResultDto
.
getServerUrl
());
state
.
putInfo
(
"httpurl"
,
uploadResultDto
.
getUrl
());
return
state
;
return
state
;
}
}
...
@@ -131,4 +149,25 @@ public class StorageManager {
...
@@ -131,4 +149,25 @@ public class StorageManager {
return
new
BaseState
(
true
);
return
new
BaseState
(
true
);
}
}
/**
* 文件到字节数组
*
* @param file 文件
* @return 字节数组
*/
private
static
byte
[]
fileToByteArray
(
File
file
)
{
try
{
byte
[]
bArray
=
new
byte
[(
int
)
file
.
length
()];
FileInputStream
fis
=
new
FileInputStream
(
file
);
fis
.
read
(
bArray
);
fis
.
close
();
file
.
delete
();
return
bArray
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"文件到字节数组,异常"
,
e
);
}
return
null
;
}
}
}
src/main/java/com/example/controller/UEditorController.java
浏览文件 @
a3beed5c
package
com
.
example
.
controller
;
package
com
.
example
.
controller
;
import
com.example.baidu.ueditor.ActionEnter
;
import
com.example.baidu.ueditor.ActionEnter
;
import
com.example.baidu.ueditor.ConfigManager
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -14,14 +11,13 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -14,14 +11,13 @@ import javax.servlet.http.HttpServletResponse;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
@Controller
@Controller
public
class
UEditorController
{
public
class
UEditorController
{
@Value
(
"${oss.host}"
)
@Value
(
"${oss.host}"
)
private
String
imageUrl
;
private
String
imageUrl
;
@Value
(
"${oss.folder}"
)
@Value
(
"${oss.folder}"
)
private
String
ossPath
;
private
String
ossPath
;
...
@@ -32,31 +28,13 @@ public class UEditorController {
...
@@ -32,31 +28,13 @@ public class UEditorController {
@RequestMapping
(
value
=
"/config"
)
@RequestMapping
(
value
=
"/config"
)
public
void
config
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
config
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
response
.
setContentType
(
"application/json"
);
response
.
setContentType
(
"application/json"
);
String
rootPath
=
request
.
getSession
().
getServletContext
().
getRealPath
(
"/"
);
String
rootPath
=
request
.
getSession
().
getServletContext
().
getRealPath
(
"/"
);
try
{
try
{
ConfigManager
configManger
=
ConfigManager
.
getInstance
(
rootPath
,
request
.
getContextPath
(),
request
.
getRequestURI
());
String
imageUrlPrefix
=(
String
)
configManger
.
getAllConfig
().
get
(
"imageUrlPrefix"
);
String
exec
=
new
ActionEnter
(
request
,
rootPath
).
exec
();
String
exec
=
new
ActionEnter
(
request
,
rootPath
).
exec
();
//exec=exec.replace("\"imageUrlPrefix\":\"https://imgb.mofangx.com/\"","'imageUrlPrefix':'"+imageUrlPrefix+"'");
exec
=
exec
.
replace
(
"{imgUrl}"
,
imageUrl
+
"/"
);
exec
=
exec
.
replace
(
"{imgUrl}"
,
imageUrl
+
"/"
);
exec
=
exec
.
replace
(
"{basePath}"
,
ossPath
);
exec
=
exec
.
replace
(
"{basePath}"
,
ossPath
);
System
.
out
.
println
(
"exec:"
+
exec
);
//exec=exec.replace("'basePath':'erp/'","'basePath':'"+ossPath+"'");
System
.
out
.
println
(
"exec:"
+
exec
);
/*if(!exec.contains("videoMaxSize")) {
JSONObject jsonConfig =new JSONObject(exec);
jsonConfig.put("url", imageUrl+jsonConfig.getString("url"));
System.out.println(jsonConfig);
exec=jsonConfig.toString();
}*/
PrintWriter
writer
=
response
.
getWriter
();
PrintWriter
writer
=
response
.
getWriter
();
writer
.
write
(
exec
);
writer
.
write
(
exec
);
writer
.
flush
();
writer
.
flush
();
...
@@ -65,4 +43,5 @@ public class UEditorController {
...
@@ -65,4 +43,5 @@ public class UEditorController {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
}
}
src/main/java/com/example/util/uploadLocalost/FileConstants.java
0 → 100644
浏览文件 @
a3beed5c
package
com
.
example
.
util
.
uploadLocalost
;
/**
* @author LGC
* @date 2024/10/23
*/
public
class
FileConstants
{
public
static
final
String
FILE_URL_NAME
=
"meiya"
;
}
src/main/java/com/example/util/uploadLocalost/FileLocalUtils.java
0 → 100644
浏览文件 @
a3beed5c
package
com
.
example
.
util
.
uploadLocalost
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.IdUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.support.StandardServletMultipartResolver
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.util.Iterator
;
/**
* 本地文件
*
* @author yangzj
* @date 2024/6/7 15:54
*/
@Slf4j
@Component
public
class
FileLocalUtils
{
@Value
(
"${file.path}"
)
private
String
filePath
=
"D:/"
;
@Value
(
"${environment}"
)
private
String
environment
=
"dev"
;
@Value
(
"${fileDomain}"
)
private
String
domain
=
"127.0.0.1:5555"
;
@Autowired
private
MultipartFileToFileLocalUse
multipartFileToFileLocalUse
;
/**
* 上传文件(HttpServletRequest)
*
* @param request HttpServletRequest
* @return 文件对象
*/
public
UploadResultDto
uploadFile
(
HttpServletRequest
request
)
throws
Exception
{
UploadResultDto
uploadResultDto
=
new
UploadResultDto
();
File
file
=
null
;
try
{
MultipartHttpServletRequest
mreq
=
new
StandardServletMultipartResolver
().
resolveMultipart
(
request
);
Iterator
<
String
>
fileNameIter
=
mreq
.
getFileNames
();
while
(
fileNameIter
.
hasNext
())
{
MultipartFile
multipartFile
=
mreq
.
getFile
(
fileNameIter
.
next
());
if
(
multipartFile
==
null
)
{
throw
new
Exception
(
"uploadFile: multipartFile == null"
);
}
file
=
multipartFileToFileLocalUse
.
multipartFileToFile
(
multipartFile
);
if
(
file
==
null
)
{
throw
new
Exception
(
"uploadFile: file == null"
);
}
// 原始名字
String
originalName
=
file
.
getName
();
uploadResultDto
.
setOrigin_name
(
originalName
);
// 判断所要上传的图片是否是图片,图片可以预览,其他文件不提供通过URL预览
// boolean isImage = ImageIO.read(file) != null;
log
.
info
(
"------本地文件上传开始--------"
+
originalName
);
String
suffix
=
originalName
.
substring
(
originalName
.
lastIndexOf
(
'.'
));
String
fileName
=
IdUtil
.
fastSimpleUUID
()
+
suffix
;
uploadResultDto
.
setName
(
fileName
);
// String date_path = DateUtil.dateToStringByFormat(DateUtil.FORMATTER_DATE_STR, new Date());
// 设置图片路径和名称(文件服务器地址)
// String serverPath="insurecore";;
// //区分环境 配置不同的方位地址 todo
// if (!isImage) {
// //文件
// serverPath = "insurecore/file";
// } else {
// //图片
// serverPath = "insurecore/image";
// }
// if (!isImage) {
// //文件
// serverPath = "insurecore/file/" + date_path;
// } else {
// //图片
// serverPath = "insurecore/image/" + date_path;
// }
String
fileUrlName
=
FileConstants
.
FILE_URL_NAME
;
String
serverUrl
=
fileUrlName
+
"/"
+
fileName
;
// 存储地址
String
fileUrl
=
filePath
+
fileUrlName
;
// 保存文件夹路径
String
url
;
// 访问URL
if
(
"dev"
.
equals
(
environment
))
{
url
=
getHttpAndPort
(
request
)
+
"/"
+
serverUrl
;
}
else
{
url
=
domain
+
serverUrl
;
}
uploadResultDto
.
setUrl
(
url
);
uploadResultDto
.
setServerUrl
(
serverUrl
);
log
.
info
(
"------本地服务器文件上传配置路径filePath: {}"
,
filePath
);
log
.
info
(
"------本地服务器文件上传保存文件夹路径fileUrl: {}"
,
fileUrl
);
log
.
info
(
"------本地服务器文件上传存储地址serverUrl: {}"
,
serverUrl
);
log
.
info
(
"------本地服务器文件上传访问URL: {}"
,
url
);
//
File
targetFile
=
new
File
(
fileUrl
);
FileUtil
.
mkdir
(
targetFile
);
File
saveFile
=
new
File
(
targetFile
,
fileName
);
//可用 未使用
//localFileToFile.localFileToFile(new FileInputStream(file), filePath + serverUrl);
//可用 使用中
multipartFile
.
transferTo
(
saveFile
);
log
.
info
(
"------本地服务器文件上传成功--------"
+
file
.
getName
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"本地服务器文件上传异常"
,
e
);
throw
new
Exception
(
"本地服务器文件上传异常"
);
}
finally
{
if
(
file
!=
null
)
{
// 删除保存在本地的临时图片
file
.
delete
();
}
}
log
.
info
(
"------本地服务器文件上传成功返回数据--------"
+
JsonUtil
.
toStr
(
uploadResultDto
));
return
uploadResultDto
;
}
/**
* 上传文件(自定义后缀)
*
* @param bytes 文件字节流
* @param suffix 文件后缀
* @return 文件对象
*/
public
UploadResultDto
uploadFile
(
byte
[]
bytes
,
String
suffix
)
{
UploadResultDto
uploadResultDto
=
new
UploadResultDto
();
try
{
log
.
info
(
"------本地文件上传开始--------"
);
String
fileName
=
IdUtil
.
fastSimpleUUID
()
+
suffix
;
uploadResultDto
.
setName
(
fileName
);
// 设置图片路径和名称(文件服务器地址)
String
fileUrlName
=
FileConstants
.
FILE_URL_NAME
;
String
serverUrl
=
fileUrlName
+
"/"
+
fileName
;
// 存储地址
String
fileUrl
=
filePath
+
fileUrlName
;
// 保存文件夹路径
String
url
;
// 访问URL
if
(
"dev"
.
equals
(
environment
))
{
url
=
"http://127.0.0.1:5555"
+
"/"
+
serverUrl
;
}
else
{
url
=
domain
+
serverUrl
;
}
uploadResultDto
.
setUrl
(
url
);
uploadResultDto
.
setServerUrl
(
serverUrl
);
log
.
info
(
"------本地服务器文件上传配置路径filePath: {}"
,
filePath
);
log
.
info
(
"------本地服务器文件上传保存文件夹路径fileUrl: {}"
,
fileUrl
);
log
.
info
(
"------本地服务器文件上传存储地址serverUrl: {}"
,
serverUrl
);
log
.
info
(
"------本地服务器文件上传访问URL: {}"
,
url
);
// 目标文件夹
File
targetFile
=
new
File
(
fileUrl
);
FileUtil
.
mkdir
(
targetFile
);
File
saveFile
=
new
File
(
targetFile
,
fileName
);
// 将文件流写入文件
try
(
FileOutputStream
writer
=
new
FileOutputStream
(
saveFile
))
{
writer
.
write
(
bytes
);
}
log
.
info
(
"------本地服务器文件上传成功--------"
+
saveFile
.
getName
());
}
catch
(
Exception
e
)
{
log
.
error
(
"本地服务器文件上传异常"
,
e
);
}
log
.
info
(
"------本地服务器文件上传成功返回数据--------"
+
JsonUtil
.
toStr
(
uploadResultDto
));
return
uploadResultDto
;
}
/**
* 上传pdf文件
*
* @param bytes pdf文件字节流
* @return 文件对象
*/
public
UploadResultDto
uploadFilePdf
(
byte
[]
bytes
)
throws
Exception
{
return
uploadFile
(
bytes
,
".pdf"
);
}
/**
* 上传图片文件
*
* @param bytes 图片文件字节流
* @return 文件对象
*/
public
UploadResultDto
uploadFileImg
(
byte
[]
bytes
,
String
suffix
)
throws
Exception
{
return
uploadFile
(
bytes
,
suffix
);
}
public
static
void
main
(
String
[]
args
)
{
//byte[] bytes = FileUtil.readBytes(new File("C:\\Users\\Administrator\\Desktop\\f5857ea3302f45519118a4c7d63e075f-电子保单1692507755377923628.pdf"));
// byte[] bytes = FileUtil.readBytes(new File("D:\\Desktop\\f5857ea3302f45519118a4c7d63e075f-电子保单1692507755377923628.pdf"));
// FileLocalUtils fileLocalUtils = new FileLocalUtils();
// UploadResultDto uploadResultDto = fileLocalUtils.uploadFilePdf(bytes);
// System.out.println(JSONUtil.toJsonStr(uploadResultDto));
String
name
=
"1a83e917a04a4848a94daccb68764307-51630CFE-A678-4A14-AAD7-33488A7E3C19.jpeg"
;
String
suffix
=
name
.
substring
(
name
.
lastIndexOf
(
'.'
));
System
.
out
.
println
(
suffix
);
}
/**
* 获得当前项目访问的地址
* 例http://127.0.0.1:8080
*
* @return 返回当前项目访问的地址
*/
public
static
String
getHttpAndPort
(
HttpServletRequest
request
)
{
return
request
.
getScheme
()
+
"://"
+
request
.
getServerName
()
+
":"
+
request
.
getServerPort
();
}
}
\ No newline at end of file
src/main/java/com/example/util/uploadLocalost/JsonUtil.java
0 → 100644
浏览文件 @
a3beed5c
package
com
.
example
.
util
.
uploadLocalost
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
public
class
JsonUtil
{
/**
* 功能描述: JSONArray到json字符串-数组类型的转换
*
* @param jsonArray JSON ARRAY
* @return JSON ARRAY
*/
public
static
String
toStr
(
JSONArray
jsonArray
)
{
return
JSONArray
.
toJSONString
(
jsonArray
);
}
/**
* 功能描述:JavaBean到json字符串-简单对象类型的转换
*
* @param object OBJECT
* @return 字符串
*/
public
static
String
toStr
(
Object
object
)
{
return
JSON
.
toJSONString
(
object
,
SerializerFeature
.
DisableCircularReferenceDetect
);
}
/**
* json字符串-简单对象型到JSONObject的转换
*
* @param json_str 要转为JSON对象的字符串
* @return JSON OBJECT
*/
private
static
JSONObject
toJsonObj
(
String
json_str
)
{
return
JSONObject
.
parseObject
(
json_str
);
}
/**
* 功能描述:json字符串-简单对象型与javaBean之间的转换
*
* @param json_str json字符串-复杂对象型
* @param type 对象类型
* @return java bean
*/
public
static
<
T
>
T
toBean
(
String
json_str
,
TypeReference
<?>
type
)
{
return
(
T
)
JSON
.
parseObject
(
json_str
,
type
);
}
/**
* 功能描述:json字符串-简单对象型与javaBean之间的转换
*
* @param json_str json字符串-简单对象型
* @param type 对象类型
* @return java bean
*/
public
static
<
T
>
T
toBean
(
String
json_str
,
Class
type
)
{
return
(
T
)
JSON
.
parseObject
(
json_str
,
type
);
}
/**
* @param json_str json 字符串
* @return 字符串
*/
public
static
StringBuilder
formatJsonStr
(
String
json_str
)
{
int
level
=
0
;
//存放格式化的json字符串
StringBuilder
jsonForMatStr
=
new
StringBuilder
();
for
(
int
index
=
0
;
index
<
json_str
.
length
();
index
++)
//将字符串中的字符逐个按行输出
{
//获取s中的每个字符
char
c
=
json_str
.
charAt
(
index
);
//level大于0并且jsonForMatStr中的最后一个字符为\n,jsonForMatStr加入\t
if
(
level
>
0
&&
'\n'
==
jsonForMatStr
.
charAt
(
jsonForMatStr
.
length
()
-
1
))
{
jsonForMatStr
.
append
(
getLevelStr
(
level
));
}
//遇到"{"和"["要增加空格和换行,遇到"}"和"]"要减少空格,以对应,遇到","要换行
switch
(
c
)
{
case
'{'
:
case
'['
:
jsonForMatStr
.
append
(
c
).
append
(
"\n"
);
level
++;
break
;
case
','
:
jsonForMatStr
.
append
(
c
).
append
(
"\n"
);
break
;
case
'}'
:
case
']'
:
jsonForMatStr
.
append
(
"\n"
);
level
--;
jsonForMatStr
.
append
(
getLevelStr
(
level
));
jsonForMatStr
.
append
(
c
);
break
;
default
:
jsonForMatStr
.
append
(
c
);
break
;
}
}
return
jsonForMatStr
;
}
/**
* 功能描述:
*
* @param level level
* @return string
*/
private
static
String
getLevelStr
(
int
level
)
{
StringBuilder
levelStr
=
new
StringBuilder
();
for
(
int
levelI
=
0
;
levelI
<
level
;
levelI
++)
{
levelStr
.
append
(
"\t"
);
}
return
levelStr
.
toString
();
}
}
src/main/java/com/example/util/uploadLocalost/MultipartFileToFileLocalUse.java
0 → 100644
浏览文件 @
a3beed5c
package
com
.
example
.
util
.
uploadLocalost
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
/**
* @Author dengkeqin
* @Date 2021/1/30 16:37
* @Version 1.0
*/
@Component
public
class
MultipartFileToFileLocalUse
{
/**
* MultipartFile 转 File
*
* @param file
* @throws Exception
*/
public
File
multipartFileToFile
(
MultipartFile
file
)
throws
Exception
{
File
toFile
=
null
;
if
(
file
.
equals
(
""
)
||
file
.
getSize
()
<=
0
)
{
file
=
null
;
}
else
{
InputStream
ins
=
null
;
ins
=
file
.
getInputStream
();
toFile
=
new
File
(
file
.
getOriginalFilename
());
inputStreamToFile
(
ins
,
toFile
);
ins
.
close
();
}
return
toFile
;
}
//获取流文件
private
void
inputStreamToFile
(
InputStream
ins
,
File
file
)
{
try
{
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
ins
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
os
.
close
();
ins
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/com/example/util/uploadLocalost/UploadResultDto.java
0 → 100644
浏览文件 @
a3beed5c
package
com
.
example
.
util
.
uploadLocalost
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 文件上传结果
**/
@Data
public
class
UploadResultDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
3118770337180675705L
;
//原始文件名称
private
String
origin_name
;
//文件名称 demo:201911025698421.jpg
private
String
name
;
//状态 demo:done
private
String
status
;
// 访问URL demo:本地开发环境:http://192.168.88.59:9999/insurecore/image/***.jpg 生产环境:https://domain.com/pic/***.jpg"
private
String
url
;
//生产文件服务器地址(存储地址) demo: 配置的地址+/insurecore/image/***.jpg
private
String
serverUrl
;
}
src/main/resources/application.properties
浏览文件 @
a3beed5c
server.port
=
5555
server.port
=
5555
#web.upload-path=E:/
spring.mvc.static-path-pattern
=
/**
spring.mvc.static-path-pattern
=
/**
spring.resources.static-locations
=
classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path}
spring.resources.static-locations
=
classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path}
imageUrl
=
https://imgb.mofangx.com/
#使用本地存储是使用
oss.host
=
https://imgb.mofangx.com
#显示地址
oss.keyId
=
LTAI5tF4FvqrAB8izKXcXZvs
imageUrl
=
http://192.168.88.59:5555/
oss.keySecret
=
fLz0od9jSnQIBLxBqdUEwHQyme8pkv
oss.host
=
oss.bucketName
=
mofang-pro
oss.keyId=
oss.folder
=
insure/
oss.keySecret
=
oss.bucketName=
oss.folder
=
#imageUrl=https://imgb.woyoubooking.com/
#使用OSS存储配置
#oss.host=https://imgb.woyoubooking.com
#imageUrl=https://imgb.mofangx.com/
#oss.keyId=LTAISxaXkVGKq7Ec
#oss.host=https://imgb.mofangx.com
#oss.keySecret=CokBrGxVPQc9v0I9TXdbqqUfHX8YYJ
#oss.keyId=LTAI5tF4FvqrAB8izKXcXZvs
#oss.bucketName=woyou-pro
#oss.keySecret=fLz0od9jSnQIBLxBqdUEwHQyme8pkv
#oss.folder=woyou/
#oss.bucketName=mofang-pro
#oss.folder=insure/
#文件保存地址(第一层)
file.path: D:/
#
etcd.server
=
http://etcd.mofang.cn:2379
#环境
\ No newline at end of file
environment
:
dev
#文件查看域名
fileDomain
:
http://127.0.0.1:5555/meiya/
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论