Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
geeeeeeeek committed May 14, 2023
0 parents commit 1a5f2be
Show file tree
Hide file tree
Showing 345 changed files with 46,471 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
my-log
98 changes: 98 additions & 0 deletions server/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Document of this project

### 功能

* 增删改查
* 文件上传
* 数据库配置
* 日志管理
* 权限控制

### 后端部署流程

1. 配置端口 位于application.yml
2. 配置数据库 位于application.yml
3. 配置location目录 位于application.yml
4. 配置静态目录 位于application.yml
5. 配置uploadPath 位于application.yml
6. 修改logback-spring.xml下的LOG_HOME的value值
7. maven clean -> maven package
8. 将jar包复制到服务器
9. 将upload文件夹复制到服务器
10. 运行启动jar包命令

### 运行命令(或双击start.sh)

title xxxx
java -jar -Xms64m -Xmx128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=64m xxxxx.jar


### 数据库相关

删除数据库命令:

drop database if exists book;

创建数据库命令:

CREATE DATABASE IF NOT EXISTS book DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

数据库备份命令:

mysqldump -u root -p --databases 数据库名称 > xxx.sql

数据库恢复命令:

source D:\\xxx.sql


### 常见问题

#### 日志路径

修改logback-spring.xml下的LOG_HOME的value值

#### 配置数据库

application.yml中

#### Druid连接池配置

* application.yml中配置druid
* 参考链接:https://blog.csdn.net/nothingavenger/article/details/114119585
* 监控地址:http://localhost:8009/druid/index.html

#### mysql主键id过长

https://blog.csdn.net/qq_46728644/article/details/120772577

#### yml不起作用

需要maven clean一下

#### 注意实体字段最好是String类型

实体字段最好是String类型,mybatis-plus的update的时候,null的不更新

#### 打包步骤

maven clean -> maven package

https://blog.csdn.net/weixin_42822484/article/details/107893586

#### 配置文件上传大小

application.yml中multipart下

#### 静态资源路径配置

https://blog.csdn.net/cylcjsg/article/details/128102776?

#### 跨域配置

见CorsConfig.java





88 changes: 88 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>springdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springdemo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 连接mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.12</version>
</dependency>
<!-- gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
<!--自启动Druid管理后台-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>



</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<!--阿里云仓库,国内速度快-->
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.test.springdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringdemoApplication {

public static void main(String[] args) {
SpringApplication.run(SpringdemoApplication.class, args);
}

}
58 changes: 58 additions & 0 deletions server/src/main/java/com/test/springdemo/common/APIResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.test.springdemo.common;


import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

/**
* @功能描述: 响应报文,统一封装类
*/
@Data
public class APIResponse<T> implements Serializable {
private int code;
private String msg;
private T data;
private String trace;
private long timestamp;

public APIResponse() {
this.timestamp = System.currentTimeMillis();
}

public APIResponse(ResponeCode responseCode) {
this.timestamp = System.currentTimeMillis();
this.code = responseCode.getCode();
this.msg = responseCode.getMsg();
}

public APIResponse(ResponeCode responseCode, String msg) {
this(responseCode);
this.msg = msg;
}

public APIResponse(ResponeCode responseCode, T data) {
this(responseCode);
this.data = data;
}

public APIResponse(ResponeCode responseCode, String msg, T data) {
this(responseCode);
this.trace = msg;
this.data = data;
}

@Override
public String toString() {
return "APIResponse{" +
"timestamp=" + timestamp +
", code=" + code +
", msg='" + msg + '\'' +
", trace='" + trace + '\'' +
", data=" + data +
//", count=" + count +
'}';
}
}
28 changes: 28 additions & 0 deletions server/src/main/java/com/test/springdemo/common/ResponeCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.test.springdemo.common;

/**
* @功能描述: 响应报文,统一封装类
*/
public enum ResponeCode {
SUCCESS(200, "成功"),
FAIL(400, "失败"),
UNAUTHORIZED(401, "未认证"),
NOT_FOUND(404, "接口不存在"),
INTERNAL_SERVER_ERROR(500, "服务器内部错误");

private int code;
private String msg;

private ResponeCode(int code, String msg) {
this.code = code;
this.msg = msg;
}

public int getCode() {
return this.code;
}

public String getMsg() {
return this.msg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.test.springdemo.common;

public class TestUtils {
}
24 changes: 24 additions & 0 deletions server/src/main/java/com/test/springdemo/config/MyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.test.springdemo.config;

import com.test.springdemo.interceptor.AccessInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")//项目中的所有接口都支持跨域
.allowedOriginPatterns("*") //所有地址都可以访问,也可以配置具体地址
.allowCredentials(true)
.allowedMethods("*");//"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
// 自定义拦截器
registry.addInterceptor(new AccessInterceptor());
}
}
Loading

0 comments on commit 1a5f2be

Please sign in to comment.