Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
400371b2
Commit
400371b2
authored
Mar 25, 2020
by
yuquan.zhu
Committed by
284718418@qq.com
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改跨域访问
parent
236ab785
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
46 deletions
+9
-46
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
+9
-46
No files found.
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
View file @
400371b2
...
...
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -35,67 +36,34 @@ public class WebSecurityConfig implements WebMvcConfigurer {
//.excludePathPatterns("/")
registry
.
addInterceptor
(
getSessionInterceptor
())
.
addPathPatterns
(
"/**"
)
.
excludePathPatterns
(
"/callback/**"
)
.
excludePathPatterns
(
"/actuator/*"
)
.
excludePathPatterns
(
"/doc*"
)
.
excludePathPatterns
(
"/v2/**"
)
.
excludePathPatterns
(
"/**/*.js"
)
.
excludePathPatterns
(
"/8timer/**"
)
.
excludePathPatterns
(
"/kqhz/OnClickAtt/**"
)
.
excludePathPatterns
(
"/kqdk/punchclock/**"
)
.
excludePathPatterns
(
"/kqz/punchclock/**"
)
.
excludePathPatterns
(
"/kqz/sauserregdata/**"
)
.
excludePathPatterns
(
"/login/*
*
"
)
.
excludePathPatterns
(
"/login/*"
)
.
excludePathPatterns
(
"/swagger*/**"
)
.
excludePathPatterns
(
"/v2/api-docs"
)
.
excludePathPatterns
(
"/druid/login*"
)
.
excludePathPatterns
(
"/app/**"
)
.
excludePathPatterns
(
"/webjars/**"
);
// registry.addInterceptor(getSessionInterceptor()).addPathPatterns("/**").excludePathPatterns("/swagger-ui*");
}
/**
* 配置消息转换器--这里我用的是alibaba 开源的 fastjson
* @param converters
*/
@Override
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
// Iterator<HttpMessageConverter<?>> iterator = converters.iterator();
// while(iterator.hasNext()){
// HttpMessageConverter<?> converter = iterator.next();
// if(converter instanceof MappingJackson2HttpMessageConverter){
// iterator.remove();
// }
// }
// 1.需要先定义一个convert 转换消息的对象
FastJsonHttpMessageConverter
fastConverter
=
new
FastJsonHttpMessageConverter
();
// 2.添加fastJson的配置信息,比如,是否需要格式化返回的json数据
FastJsonConfig
fastJsonConfig
=
new
FastJsonConfig
();
// 时间格式化
fastJsonConfig
.
setDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
// fastJsonConfig.setDateFormat("yyyy-MM-dd");
// 空值特别处理
// WriteNullListAsEmpty 将Collection类型字段的字段空值输出为[]
// WriteNullStringAsEmpty 将字符串类型字段的空值输出为空字符串 ""
// WriteNullNumberAsZero 将数值类型字段的空值输出为0
// WriteNullBooleanAsFalse 将Boolean类型字段的空值输出为false
fastJsonConfig
.
setSerializerFeatures
(
SerializerFeature
.
PrettyFormat
// SerializerFeature.WriteEnumUsingToString,
// SerializerFeature.WriteNullStringAsEmpty,
// SerializerFeature.WriteMapNullValue,
// SerializerFeature.WriteDateUseDateFormat
);
// fastJsonConfig.setSerializeFilters((ValueFilter) (o, s, source) -> {
// if (source == null) {
// return "";//此处是关键,如果返回对象的变量为null,则自动变成""
// }
// if (source instanceof Date) {
// return ((Date) source).getTime();
// }
// return source;
// });
fastJsonConfig
.
setSerializerFeatures
(
SerializerFeature
.
PrettyFormat
,
SerializerFeature
.
WriteNullListAsEmpty
,
SerializerFeature
.
WriteNullStringAsEmpty
);
// 处理中文乱码问题
List
<
MediaType
>
fastMediaTypes
=
new
ArrayList
<>();
fastMediaTypes
.
add
(
MediaType
.
APPLICATION_JSON_UTF8
);
...
...
@@ -103,7 +71,7 @@ public class WebSecurityConfig implements WebMvcConfigurer {
// 3.在convert中添加配置信息
fastConverter
.
setFastJsonConfig
(
fastJsonConfig
);
// 4.将convert添加到converters当中
converters
.
add
(
0
,
fastConverter
);
converters
.
add
(
fastConverter
);
}
...
...
@@ -114,16 +82,11 @@ public class WebSecurityConfig implements WebMvcConfigurer {
// @Override
// public void addCorsMappings(CorsRegistry registry) {
//// System.out.println("我是MyWebConfig跨域");
// //设置允许跨域的路径
// registry.addMapping("/**")
// //设置允许跨域请求的域名
// .allowedOrigins("*")
// //是否允许证书 不再默认开启
// .allowCredentials(true)
// //设置允许的方法
// .allowedMethods("*")
// //跨域允许时间
// .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
// .maxAge(3600);
// }
}
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