使用springboot遇到的问题

1、跨域配置

// 请求跨域
@Configuration
public class CorsConfig implements WebMvcConfigurer {

static final String ORIGINS[] = new String[] { "GET", "POST", "PUT", "DELETE" };

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 所有的当前站点的请求地址,都支持跨域访问。
.allowedOriginPatterns("*") // 所有的外部域都可跨域访问。 如果是localhost则很难配置,因为在跨域请求的时候,外部域的解析可能是localhost、127.0.0.1、主机名
.allowCredentials(true) // 是否支持跨域用户凭证
.allowedMethods(ORIGINS) // 当前站点支持的跨域请求类型是什么
.maxAge(3600); // 超时时长设置为1小时。 时间单位是秒。
}
}
2、请求接口出现401错误
删除pom文件中的security模块,然后reimport maven依赖就可以了,重新导入依赖是必须要做的。
3、接口函数的参数上写上@RequestBody,这样才能将页面传过来的内容转化成对象类型。
4、使用lombok的时候,idea需要安装插件,这样才不会报get、set方法找不到的编译错误
5、lombok使用
@AllArgsConstructor可以创建出全部参数的构造方法

2、redis配置

    https://www.cnblogs.com/zeng1994/p/03303c805731afc9aa9c60dbbd32a323.html

posted @ 2021-09-06 11:35  菜逼黑  阅读(139)  评论(0编辑  收藏  举报