98 lines
2.5 KiB
Markdown
98 lines
2.5 KiB
Markdown
|
|
# 后端初始化
|
|||
|
|
|
|||
|
|
## 跨域问题
|
|||
|
|
|
|||
|
|
前端与后端的端口号不一致----》跨域问题
|
|||
|
|
|
|||
|
|
### 解决方案
|
|||
|
|
|
|||
|
|
- 后端来支持跨域
|
|||
|
|
- 代理 nginx 第三方脚手架
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
package com.zds.zds_picture_backend.conifg;/*
|
|||
|
|
*@auther 郑笃实
|
|||
|
|
*@version 1.0
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
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 CorsConfig implements WebMvcConfigurer {
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|||
|
|
// 覆盖所有请求
|
|||
|
|
registry.addMapping("/**")
|
|||
|
|
// 允许发送 Cookie
|
|||
|
|
.allowCredentials(true)
|
|||
|
|
// 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突)
|
|||
|
|
.allowedOriginPatterns("*")
|
|||
|
|
// 放行哪些请求方式
|
|||
|
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|||
|
|
// 放行哪些请求头
|
|||
|
|
.allowedHeaders("*")
|
|||
|
|
// 暴露哪些响应头
|
|||
|
|
.exposedHeaders("*");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
使用这个就可以让解决跨域问题
|
|||
|
|
|
|||
|
|
## lombok报错
|
|||
|
|
|
|||
|
|
[【已解决】java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have-CSDN博客](https://blog.csdn.net/weixin_36829761/article/details/136287081)
|
|||
|
|
|
|||
|
|
```xml
|
|||
|
|
<!-- Lombok:只保留一条,provided;由 compiler plugin 负责 annotation processing -->
|
|||
|
|
<dependency>
|
|||
|
|
<groupId>org.projectlombok</groupId>
|
|||
|
|
<artifactId>lombok</artifactId>
|
|||
|
|
<version>${lombok.version}</version>
|
|||
|
|
<scope>provided</scope>
|
|||
|
|
</dependency>
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
## @MapperScan("com.zds.zds_picture_backend.mapper")
|
|||
|
|
|
|||
|
|
这是mybatis-plus的注解,用于扫描mapper接口
|
|||
|
|
|
|||
|
|
mapper层是针对数据库的
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
## 在进行跨域以后前后端依旧不连通
|
|||
|
|
|
|||
|
|
那有可能是 前端发送的是HTTPS的 而后端springboot内置的tomcat是只能支持http协议的 协议不同所有可能导致前端调用后端的时候出现问题
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
## LoginUserVO
|
|||
|
|
|
|||
|
|
```java
|
|||
|
|
public LoginUserVO userLogin(String userAccount, String userPassword, HttpServletRequest request)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
为什么需要这个 ```HttpServletRequest request``` 因为我们登录账号的时候需要给他种session 所以我们需要request
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
## id精度问题
|
|||
|
|
|
|||
|
|

|
|||
|
|
|
|||
|
|
从后端调出来的id精度可能跟后端的精度不一致,甚至可能会导致json中的和展示的不一样
|
|||
|
|
|
|||
|
|
|
|||
|
|
|