Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
gs1-office-web-sit
Commits
ac993fce
Commit
ac993fce
authored
Oct 12, 2021
by
吴迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
磁盘映射、文件上传
parent
4af53a29
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
275 additions
and
65 deletions
+275
-65
ErrorCodeEnum.java
src/main/java/io/office/common/enumpack/ErrorCodeEnum.java
+37
-0
RRException.java
src/main/java/io/office/common/exception/RRException.java
+8
-0
SwaggerConfig.java
src/main/java/io/office/config/SwaggerConfig.java
+62
-62
WebMvcConfig.java
src/main/java/io/office/config/WebMvcConfig.java
+20
-0
WebMvcConfig.java
src/main/java/io/office/modules/app/config/WebMvcConfig.java
+19
-0
FileController.java
...a/io/office/modules/manage/controller/FileController.java
+31
-0
NewsColumnServiceImpl.java
...ce/modules/manage/service/impl/NewsColumnServiceImpl.java
+9
-1
DateUtils.java
src/main/java/io/office/modules/manage/utils/DateUtils.java
+0
-0
UploadUtils.java
...main/java/io/office/modules/manage/utils/UploadUtils.java
+77
-0
application-dev.yml
src/main/resources/application-dev.yml
+12
-2
No files found.
src/main/java/io/office/common/enumpack/ErrorCodeEnum.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
common
.
enumpack
;
/**
*
* @description:
*
* @author wudi
* @date 22:08 2021/10/12
*/
public
enum
ErrorCodeEnum
{
SUCCESS
(
0
,
"成功"
),
//成功
FAIL
(-
1
,
"失败"
),
//失败
FILE_IS_NULL
(
10001
,
"上传文件不能为空!"
);
private
Integer
code
;
private
String
msg
;
ErrorCodeEnum
(
int
code
)
{
this
.
code
=
code
;
}
ErrorCodeEnum
(
Integer
code
,
String
message
)
{
this
.
code
=
code
;
this
.
msg
=
message
;
}
public
Integer
code
()
{
return
this
.
code
;
}
public
String
message
()
{
return
this
.
msg
;
}
}
src/main/java/io/office/common/exception/RRException.java
View file @
ac993fce
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
package
io
.
office
.
common
.
exception
;
package
io
.
office
.
common
.
exception
;
import
io.office.common.enumpack.ErrorCodeEnum
;
/**
/**
* 自定义异常
* 自定义异常
*
*
...
@@ -41,6 +43,12 @@ public class RRException extends RuntimeException {
...
@@ -41,6 +43,12 @@ public class RRException extends RuntimeException {
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
RRException
(
ErrorCodeEnum
errorCodeEnum
)
{
super
(
errorCodeEnum
.
message
());
this
.
code
=
errorCodeEnum
.
code
();
this
.
msg
=
errorCodeEnum
.
message
();
}
public
String
getMsg
()
{
public
String
getMsg
()
{
return
msg
;
return
msg
;
}
}
...
...
src/main/java/io/office/config/SwaggerConfig.java
View file @
ac993fce
/**
///**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
// * Copyright (c) 2016-2019 人人开源 All rights reserved.
*
// *
* https://www.renren.io
// * https://www.renren.io
*
// *
* 版权所有,侵权必究!
// * 版权所有,侵权必究!
*/
// */
//
package
io
.
office
.
config
;
//package io.office.config;
//
import
io.swagger.annotations.ApiOperation
;
//import io.swagger.annotations.ApiOperation;
import
org.springframework.context.annotation.Bean
;
//import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
//import org.springframework.context.annotation.Configuration;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import
springfox.documentation.builders.ApiInfoBuilder
;
//import springfox.documentation.builders.ApiInfoBuilder;
import
springfox.documentation.builders.PathSelectors
;
//import springfox.documentation.builders.PathSelectors;
import
springfox.documentation.builders.RequestHandlerSelectors
;
//import springfox.documentation.builders.RequestHandlerSelectors;
import
springfox.documentation.service.ApiInfo
;
//import springfox.documentation.service.ApiInfo;
import
springfox.documentation.service.ApiKey
;
//import springfox.documentation.service.ApiKey;
import
springfox.documentation.spi.DocumentationType
;
//import springfox.documentation.spi.DocumentationType;
import
springfox.documentation.spring.web.plugins.Docket
;
//import springfox.documentation.spring.web.plugins.Docket;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
//
import
java.util.List
;
//import java.util.List;
//
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
//import static com.google.common.collect.Lists.newArrayList;
//
@Configuration
//@Configuration
@EnableSwagger2
//@EnableSwagger2
public
class
SwaggerConfig
implements
WebMvcConfigurer
{
//public class SwaggerConfig implements WebMvcConfigurer {
//
@Bean
// /* @Bean
public
Docket
createRestApi
()
{
// public Docket createRestApi() {
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
// return new Docket(DocumentationType.SWAGGER_2)
.
apiInfo
(
apiInfo
())
// .apiInfo(apiInfo())
.
select
()
// .select()
//加了ApiOperation注解的类,才生成接口文档
// //加了ApiOperation注解的类,才生成接口文档
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//包下的类,才生成接口文档
// //包下的类,才生成接口文档
//.apis(RequestHandlerSelectors.basePackage("io.renren.controller"))
// //.apis(RequestHandlerSelectors.basePackage("io.renren.controller"))
.
paths
(
PathSelectors
.
any
())
// .paths(PathSelectors.any())
.
build
()
// .build()
.
securitySchemes
(
security
());
// .securitySchemes(security());
}
// }
//
private
ApiInfo
apiInfo
()
{
// private ApiInfo apiInfo() {
return
new
ApiInfoBuilder
()
// return new ApiInfoBuilder()
.
title
(
"人人开源"
)
// .title("人人开源")
.
description
(
"renren-fast文档"
)
// .description("renren-fast文档")
.
termsOfServiceUrl
(
"https://www.renren.io"
)
// .termsOfServiceUrl("https://www.renren.io")
.
version
(
"3.0.0"
)
// .version("3.0.0")
.
build
();
// .build();
}
// }
//
private
List
<
ApiKey
>
security
()
{
// private List<ApiKey> security() {
return
newArrayList
(
// return newArrayList(
new
ApiKey
(
"token"
,
"token"
,
"header"
)
// new ApiKey("token", "token", "header")
);
// );
}
// }*/
//
}
//}
\ No newline at end of file
\ No newline at end of file
src/main/java/io/office/config/WebMvcConfig.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
/**
* TODO
*
* @author wudi
* @version 1.0
* @date 2021/3/24 9:44
*/
//@Configuration
public
class
WebMvcConfig
extends
WebMvcConfigurerAdapter
{
}
src/main/java/io/office/modules/app/config/WebMvcConfig.java
View file @
ac993fce
...
@@ -11,9 +11,11 @@ package io.office.modules.app.config;
...
@@ -11,9 +11,11 @@ package io.office.modules.app.config;
import
io.office.modules.app.interceptor.AuthorizationInterceptor
;
import
io.office.modules.app.interceptor.AuthorizationInterceptor
;
import
io.office.modules.app.resolver.LoginUserHandlerMethodArgumentResolver
;
import
io.office.modules.app.resolver.LoginUserHandlerMethodArgumentResolver
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.List
;
import
java.util.List
;
...
@@ -25,6 +27,11 @@ import java.util.List;
...
@@ -25,6 +27,11 @@ import java.util.List;
*/
*/
@Configuration
@Configuration
public
class
WebMvcConfig
implements
WebMvcConfigurer
{
public
class
WebMvcConfig
implements
WebMvcConfigurer
{
@Value
(
"${request.upload.file.prefix}"
)
private
String
requestUploadFilePrefix
;
@Value
(
"${file.save.path}"
)
private
String
fileSavePath
;
@Autowired
@Autowired
private
AuthorizationInterceptor
authorizationInterceptor
;
private
AuthorizationInterceptor
authorizationInterceptor
;
@Autowired
@Autowired
...
@@ -39,4 +46,15 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -39,4 +46,15 @@ public class WebMvcConfig implements WebMvcConfigurer {
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
argumentResolvers
.
add
(
loginUserHandlerMethodArgumentResolver
);
argumentResolvers
.
add
(
loginUserHandlerMethodArgumentResolver
);
}
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
//注意前面要加file,不然是访问不了的
registry
.
addResourceHandler
(
"/"
+
requestUploadFilePrefix
+
"/**"
).
addResourceLocations
(
"file"
+
":"
+
fileSavePath
);
}
}
}
\ No newline at end of file
src/main/java/io/office/modules/manage/controller/FileController.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
controller
;
import
io.office.common.utils.R
;
import
io.office.modules.manage.utils.UploadUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
/**
*
* @description:
*
* @author wudi
* @date 22:03 2021/10/12
*/
@RestController
@RequestMapping
(
value
=
"/file"
)
@Slf4j
public
class
FileController
{
@Autowired
private
UploadUtils
uploadUtils
;
@PostMapping
(
"/uploadFile"
)
public
R
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
return
R
.
ok
().
put
(
"data"
,
uploadUtils
.
fileUpload
(
file
));
}
}
src/main/java/io/office/modules/manage/service/impl/NewsColumnServiceImpl.java
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
service
.
impl
;
package
io
.
office
.
modules
.
manage
.
service
.
impl
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
@@ -16,14 +17,20 @@ import io.office.modules.manage.service.NewsColumnService;
...
@@ -16,14 +17,20 @@ import io.office.modules.manage.service.NewsColumnService;
@Service
(
"newsColumnService"
)
@Service
(
"newsColumnService"
)
public
class
NewsColumnServiceImpl
extends
ServiceImpl
<
NewsColumnDao
,
NewsColumnEntity
>
implements
NewsColumnService
{
public
class
NewsColumnServiceImpl
extends
ServiceImpl
<
NewsColumnDao
,
NewsColumnEntity
>
implements
NewsColumnService
{
@Override
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
NewsColumnEntity
>
page
=
this
.
page
(
IPage
<
NewsColumnEntity
>
page
=
this
.
page
(
new
Query
<
NewsColumnEntity
>().
getPage
(
params
),
new
Query
<
NewsColumnEntity
>().
getPage
(
params
),
new
QueryWrapper
<
NewsColumnEntity
>()
new
QueryWrapper
<
NewsColumnEntity
>()
);
);
return
new
PageUtils
(
page
);
return
new
PageUtils
(
page
);
}
}
}
}
\ No newline at end of file
src/main/java/io/office/modules/manage/utils/DateUtils.java
0 → 100644
View file @
ac993fce
This diff is collapsed.
Click to expand it.
src/main/java/io/office/modules/manage/utils/UploadUtils.java
0 → 100644
View file @
ac993fce
package
io
.
office
.
modules
.
manage
.
utils
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
io.office.common.enumpack.ErrorCodeEnum
;
import
io.office.common.exception.RRException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
/**
* TODO
*
* @author wudi
* @version 1.0
* @date 2021/3/19 18:50
*/
@Slf4j
@Component
public
class
UploadUtils
{
@Value
(
"${file.save.path}"
)
private
String
fileSavePath
;
/* @Value("${file.save.type}")
private List fileSaveTypeList;*/
@Value
(
"${file.request.prefix}"
)
private
String
fileRequestPrefix
;
/**
* @param file 上传的文件
* @return
* @描述:上传文件到临时目录
*/
public
String
fileUpload
(
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
new
RRException
(
ErrorCodeEnum
.
FILE_IS_NULL
);
}
String
filename
=
""
;
//String originalFilename = file.getOriginalFilename();
filename
=
file
.
getOriginalFilename
();
File
fileDir
=
new
File
(
fileSavePath
+
DateUtils
.
formatDateToString
(
new
Date
(),
DateUtils
.
FORMAT4
)
+
"/"
);
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
();
}
String
dateDirPath
=
DateUtils
.
formatDateToString
(
new
Date
(),
DateUtils
.
FORMAT4
);
String
returnFilename
=
fileRequestPrefix
+
dateDirPath
+
"/"
+
filename
;
filename
=
fileSavePath
+
dateDirPath
+
"/"
+
filename
;
File
dest
=
new
File
(
filename
);
try
{
file
.
transferTo
(
dest
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
returnFilename
;
}
/**
* 根据全路径名获取businessId
* "http://10.0.20.46:6051/emgcysys/uploadFile/2021-03-23/1374288822837604352.JAVA核心面试知识整理.pdf",
*/
// public static void main(String[] args) {
// System.out.println(getBusinessIdByFullPath("http://10.0.20.46:6051/emgcysys/uploadFile/2021-03-23" +
// "/1374288822837604352.JAVA核心面试知识整理.pdf"));
// }
}
src/main/resources/application-dev.yml
View file @
ac993fce
...
@@ -47,4 +47,15 @@ spring:
...
@@ -47,4 +47,15 @@ spring:
# username: renren
# username: renren
server
:
server
:
port
:
9091
port
:
9091
# password: 123456
# password: 123456
\ No newline at end of file
#自定义文件上传路径
request
:
upload
:
file
:
prefix
:
uploadFileResource
file
:
save
:
path
:
F:/
request
:
prefix
:
http://localhost:9091/office/uploadFileResource/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment