Skip to content

Commit

Permalink
看看是否能解决数据库乱码的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
13874889161 committed Jun 19, 2020
1 parent 57a2604 commit ecac461
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
75 changes: 38 additions & 37 deletions src/main/java/com/lemon/handler/CorsFilterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,49 @@
@ServletComponentScan
public class CorsFilterConfig implements Filter {

private static final Logger logger = LoggerFactory.getLogger(CorsFilterConfig.class);
private static final Logger logger = LoggerFactory.getLogger(CorsFilterConfig.class);

private static String[] allowDomains = {"https://localhost:8080", "https://localhost:80", "https://ip:8080", "https://ip:80",
"https://ip:8080", "https://ip:80"};
private static String[] allowDomains = { "https://localhost:8080", "https://localhost:80", "https://ip:8080",
"https://ip:80", "https://ip:8080", "https://ip:80" };

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST,GET,PATCH,DELETE,PUT,OPTIONS");
/*
* 该字段可选,用来指定本次预检请求的有效期,单位为秒。上面结果中,有效期是1小时(3600秒),
* 即允许缓存该条回应3600秒(即1小时),在此期间,不用发出另一条预检请求。
*/
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
response.setHeader("Content-Type", "application/json;charset=UTF-8");
// prefight请求
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus(200);
return;
}
chain.doFilter(req, res);
}

HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST,GET,PATCH,DELETE,PUT,OPTIONS");
/*
* 该字段可选,用来指定本次预检请求的有效期,单位为秒。上面结果中,有效期是1小时(3600秒),
* 即允许缓存该条回应3600秒(即1小时),在此期间,不用发出另一条预检请求。
*/
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
response.setHeader("Content-Type","application/json;charset=UTF-8");
// prefight请求
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus( 200 );
return;
}
chain.doFilter(req, res);
}
@Override
public void destroy() {

@Override
public void destroy() {
}

}

// @Override
// public void doFilter1(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
// throws IOException, ServletException {
// // TODO Auto-generated method stub
//
// }
// @Override
// public void doFilter1(ServletRequest arg0, ServletResponse arg1,
// FilterChain arg2)
// throws IOException, ServletException {
// // TODO Auto-generated method stub
//
// }
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:https://localhost:3306/testplatform
url: jdbc:mysql:https://localhost:3306/testplatform?useUnicode=true&characterEncoding=UTF-8
username: root
password: 443321

Expand Down

0 comments on commit ecac461

Please sign in to comment.