-
使用spring mvc解决跨域问题
之前的解决方案
1
2
3
4
5
6
7
8
9
10
11
12
public class CORSConfig extends WebMvcConfigurerAdapter {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")//设置允许跨域的路径
.allowedOrigins("*")//设置允许跨域请求的域名
.allowCredentials(true)//是否允许证书 不再默认开启
.allowedMethods("GET", "POST", "PUT","PATCH", "DELETE")//设置允许的方法
.maxAge(3600);//跨域允许时间
}
}由于
WebMvcConfigurerAdapter
类过时所以使用如下方法实现
1
2
3
4
5
6
7
8
9
10
11
12
13
public class CORSConfig implements WebMvcConfigurer {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")//设置允许跨域的路径
.allowedOrigins("*")//设置允许跨域请求的域名
.allowCredentials(true)//是否允许证书 不再默认开启
.allowedMethods("GET", "POST", "PUT","PATCH", "DELETE")//设置允许的方法
.maxAge(3600);//跨域允许时间
}
} -
SpringDataJpa分页接口Pageable的实现类PageRequest构造方法弃用
old
1
new PageRequest(firstResult, maxResults, new Sort(...))
new
1
PageRequest.of(firstResult, maxResults, new Sort(...))