Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cms_sys
Project
Project
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
西魏
cms_sys
Commits
c8be6e2f
Commit
c8be6e2f
authored
Aug 24, 2019
by
sgjj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自定义上传
parent
d7517fb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
14 deletions
+32
-14
WebConfig.java
src/main/java/net/mingsoft/config/WebConfig.java
+32
-14
No files found.
src/main/java/net/mingsoft/config/WebConfig.java
View file @
c8be6e2f
...
@@ -6,6 +6,7 @@ import org.springframework.aop.Advisor;
...
@@ -6,6 +6,7 @@ import org.springframework.aop.Advisor;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
org.springframework.aop.support.DefaultPointcutAdvisor
;
import
org.springframework.aop.support.DefaultPointcutAdvisor
;
import
org.springframework.aop.support.JdkRegexpMethodPointcut
;
import
org.springframework.aop.support.JdkRegexpMethodPointcut
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
...
@@ -31,6 +32,16 @@ import net.mingsoft.basic.util.BasicUtil;
...
@@ -31,6 +32,16 @@ import net.mingsoft.basic.util.BasicUtil;
@Configuration
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
public
class
WebConfig
implements
WebMvcConfigurer
{
/**
* 上传路径
*/
@Value
(
"${ms.upload.path}"
)
private
String
uploadFloderPath
;
/**
* 上传路径映射
*/
@Value
(
"${ms.upload.mapping}"
)
private
String
uploadMapping
;
@Bean
@Bean
public
ActionInterceptor
actionInterceptor
()
{
public
ActionInterceptor
actionInterceptor
()
{
return
new
ActionInterceptor
();
return
new
ActionInterceptor
();
...
@@ -56,21 +67,28 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -56,21 +67,28 @@ public class WebConfig implements WebMvcConfigurer {
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
//jar包方式映射处理
//jar包方式映射处理
String
classPath
=
BasicUtil
.
getClassPath
(
""
);
String
classPath
=
BasicUtil
.
getClassPath
(
""
);
//jar包获取的路径带有file
if
(
classPath
.
startsWith
(
"file"
))
{
if
(
classPath
.
startsWith
(
"file"
))
{
registry
.
addResourceHandler
(
"/upload/**"
).
addResourceLocations
(
"file:"
+
BasicUtil
.
getRealPath
(
"upload"
)
+
File
.
separator
);
//判断是否设置的绝对路径
registry
.
addResourceHandler
(
"/html/**"
).
addResourceLocations
(
"file:"
+
BasicUtil
.
getRealPath
(
"html"
)
+
File
.
separator
);
registry
.
addResourceHandler
(
"/html/**"
).
addResourceLocations
(
"file:"
+
BasicUtil
.
getRealPath
(
"html"
)
+
File
.
separator
);
registry
.
addResourceHandler
(
"/templets/**"
).
addResourceLocations
(
"file:"
+
BasicUtil
.
getRealPath
(
"templets"
)
+
File
.
separator
);
registry
.
addResourceHandler
(
"/templets/**"
).
addResourceLocations
(
"file:"
+
BasicUtil
.
getRealPath
(
"templets"
)
+
File
.
separator
);
}
else
{
registry
.
addResourceHandler
(
"/app/**"
).
addResourceLocations
(
"classpath:/app/"
);
//必须做判断,不然jar运行的html路径会被覆盖掉
registry
.
addResourceHandler
(
"/api/**"
).
addResourceLocations
(
"classpath:/api/"
);
registry
.
addResourceHandler
(
"/html/**"
).
addResourceLocations
(
"/html/"
);
}
//如果是绝对路径添加映射
if
(
uploadFloderPath
.
startsWith
(
"file:"
)){
//如果指定了绝对路径,上传的文件都映射到uploadMapping下
registry
.
addResourceHandler
(
uploadMapping
).
addResourceLocations
(
uploadFloderPath
+
File
.
separator
//映射其他路径文件
//,file:F://images
);
}
}
registry
.
addResourceHandler
(
"/app/**"
).
addResourceLocations
(
"/app/"
,
"classpath:/app/"
);
registry
.
addResourceHandler
(
"/static/**"
).
addResourceLocations
(
"/static/"
,
"classpath:/static/"
);
registry
.
addResourceHandler
(
"/static/**"
).
addResourceLocations
(
"/static/"
,
"classpath:/static/"
);
registry
.
addResourceHandler
(
"/api/**"
).
addResourceLocations
(
"/api/"
,
"classpath:/api/"
);
}
}
/**
/**
* druidServlet注册
* druidServlet注册
*/
*/
@Bean
@Bean
public
ServletRegistrationBean
druidServletRegistration
()
{
public
ServletRegistrationBean
druidServletRegistration
()
{
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
StatViewServlet
());
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
StatViewServlet
());
...
@@ -132,9 +150,9 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -132,9 +150,9 @@ public class WebConfig implements WebMvcConfigurer {
return
new
DefaultPointcutAdvisor
(
druidStatPointcut
(),
druidStatInterceptor
());
return
new
DefaultPointcutAdvisor
(
druidStatPointcut
(),
druidStatInterceptor
());
}
}
/**
//
/**
* xssFilter注册
//
* xssFilter注册
*/
//
*/
// @Bean
// @Bean
// public FilterRegistrationBean xssFilterRegistration() {
// public FilterRegistrationBean xssFilterRegistration() {
// XSSEscapeFilter xssFilter = new XSSEscapeFilter();
// XSSEscapeFilter xssFilter = new XSSEscapeFilter();
...
@@ -156,7 +174,7 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -156,7 +174,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
registry
.
addViewController
(
"/"
).
setViewName
(
"forward:/index"
);
registry
.
addViewController
(
"/"
).
setViewName
(
"forward:/index"
);
registry
.
setOrder
(
Ordered
.
HIGHEST_PRECEDENCE
);
registry
.
setOrder
(
Ordered
.
HIGHEST_PRECEDENCE
);
WebMvcConfigurer
.
super
.
addViewControllers
(
registry
);
WebMvcConfigurer
.
super
.
addViewControllers
(
registry
);
}
}
}
}
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