bug 解决

前后端分离跨域问题

1
@CrossOrigin(origins = {"http://127.0.0.1:5173/"}, allowCredentials = "true")

或者添加配置类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfg implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
//设置允许跨域的路径
registry.addMapping("/**")
//设置允许跨域请求的域名
.allowedOrigins("http://127.0.0.1:9527","http://127.0.0.1:8000")
//是否允许证书 不再默认开启
.allowCredentials(true)
//设置允许的方法
.allowedMethods("*")
//跨域允许时间
.maxAge(3600);
}
}

1.添加依赖

1
2
3
4
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
  1. 添加配置类

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    package com.yupi.yupao.config;

    import org.springframework.boot.autoconfigure.session.DefaultCookieSerializerCustomizer;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.session.MapSessionRepository;
    import org.springframework.session.SessionRepository;
    import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
    import org.springframework.session.web.http.DefaultCookieSerializer;

    import java.util.concurrent.ConcurrentHashMap;

    @Configuration
    @EnableSpringHttpSession
    public class SessionConfig {
    @Bean
    public SessionRepository sessionRepository() {
    return new MapSessionRepository(new ConcurrentHashMap<>());
    }

    @Bean
    DefaultCookieSerializerCustomizer cookieSerializerCustomizer() {
    return new DefaultCookieSerializerCustomizer() {
    @Override
    public void customize(DefaultCookieSerializer cookieSerializer) {
    cookieSerializer.setSameSite("None");
    cookieSerializer.setUseSecureCookie(true); // 此项必须,否则set-cookie会被chrome浏览器阻拦
    }
    };
    }
    }

加入加密队伍时,密码没正确验证

修改 TeamServiceimpl 中 JoinTeam()

1
2
3
4
5
6
7
String password = team.getPassword();
String requestPassword = teamJoinRequest.getPassword();
if(TeamStatusEnum.SECRET.equals(teamStatusEnum)){
if(StringUtils.isBlank(requestPassword) || !requestPassword.equals(team.getPassword())){
throw new BusinessException(ErrorCode.PARAMS_ERROR, "队伍密码错误");
}
}

JSON.parse

==SyntaxError: JSON.parse: unexpected character at line 1 colimn 2 of the JSON==

JSON.parse 标准格式为单引号包裹双引号的格式 如 [“男”, “大一”], 而 ==[‘南宁’, ‘本地’]== 则会报错

参考地址:https://www.runoob.com/json/json-parse.html