Compare commits
10 Commits
2c8d065d2a
...
762e8c7123
| Author | SHA1 | Date | |
|---|---|---|---|
| 762e8c7123 | |||
| e1879902ea | |||
| 92dd52fbb4 | |||
| 49067e6b19 | |||
| b41b2f9c51 | |||
| c92882bcbf | |||
| 8cf9f23f64 | |||
| 81508c5b5d | |||
| 3cc67272a6 | |||
| ffb1e8eac5 |
0
public/api/i/2025/09/18/119exsd-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 206 KiB |
0
public/api/i/2025/09/20/10gf9ih-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
0
public/api/i/2025/09/20/10gsu60-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
0
public/api/i/2025/09/20/10h4100-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
0
public/api/i/2025/09/20/10hjla3-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
0
public/api/i/2025/09/20/10hnekj-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
0
public/api/i/2025/09/20/10i2nlq-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
0
public/api/i/2025/09/20/10i6pio-1.webp
Normal file → Executable file
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
BIN
public/api/i/2025/09/21/12fnqrb-1.webp
Executable file
|
After Width: | Height: | Size: 20 KiB |
BIN
public/api/i/2025/09/21/u993u3-1.webp
Executable file
|
After Width: | Height: | Size: 52 KiB |
BIN
public/api/i/2025/09/21/ua8smj-1.webp
Executable file
|
After Width: | Height: | Size: 29 KiB |
BIN
public/api/i/2025/09/21/uab784-1.webp
Executable file
|
After Width: | Height: | Size: 22 KiB |
BIN
public/api/i/2025/09/21/uduata-1.webp
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
public/api/i/2025/09/21/ukxf35-1.webp
Executable file
|
After Width: | Height: | Size: 19 KiB |
BIN
public/api/i/2025/09/21/wedsm1-1.webp
Executable file
|
After Width: | Height: | Size: 78 KiB |
BIN
public/api/i/2025/09/21/x6dk9p-1.webp
Executable file
|
After Width: | Height: | Size: 39 KiB |
BIN
public/api/i/2025/09/21/x6ftip-1.webp
Executable file
|
After Width: | Height: | Size: 32 KiB |
BIN
public/api/i/2025/09/21/x6htww-1.webp
Executable file
|
After Width: | Height: | Size: 22 KiB |
BIN
public/api/i/2025/09/21/x7ivoo-1.webp
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
public/api/i/2025/09/21/x7kr9o-1.webp
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
public/api/i/2025/09/21/xev89u-1.webp
Executable file
|
After Width: | Height: | Size: 30 KiB |
BIN
public/api/i/2025/09/21/xfutn8-1.webp
Executable file
|
After Width: | Height: | Size: 20 KiB |
BIN
public/api/i/2025/09/21/xfwwfm-1.webp
Executable file
|
After Width: | Height: | Size: 25 KiB |
BIN
public/api/i/2025/09/21/xfy5w7-1.webp
Executable file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
public/api/i/2025/09/21/xg132o-1.webp
Executable file
|
After Width: | Height: | Size: 16 KiB |
BIN
public/api/i/2025/09/21/xg1u42-1.webp
Executable file
|
After Width: | Height: | Size: 12 KiB |
BIN
public/api/i/2025/09/21/xg3flm-1.webp
Executable file
|
After Width: | Height: | Size: 10 KiB |
BIN
public/api/i/2025/09/21/xhd3rc-1.webp
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
public/api/i/2025/09/22/119mzz1-1.webp
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
public/api/i/2025/09/22/119q2ig-1.webp
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
public/api/i/2025/09/22/11abnz9-1.webp
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
public/api/i/2025/09/22/i8sx9o-1.webp
Executable file
|
After Width: | Height: | Size: 43 KiB |
BIN
public/api/i/2025/09/22/ia3jrw-1.webp
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
public/api/i/2025/09/22/ib38t6-1.webp
Executable file
|
After Width: | Height: | Size: 73 KiB |
BIN
public/api/i/2025/09/22/ib4quq-1.webp
Executable file
|
After Width: | Height: | Size: 48 KiB |
BIN
public/api/i/2025/09/22/ib9eq3-1.webp
Executable file
|
After Width: | Height: | Size: 20 KiB |
BIN
public/api/i/2025/09/22/ibdvwc-1.webp
Executable file
|
After Width: | Height: | Size: 90 KiB |
BIN
public/api/i/2025/09/22/ibpwz6-1.webp
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
public/api/i/2025/09/22/nk3hly-1.webp
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
public/api/i/2025/09/22/nker0x-1.webp
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
public/api/i/2025/09/22/nkq0yb-1.webp
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
public/api/i/2025/09/22/nl2e0e-1.webp
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/api/i/2025/09/22/nq0cv2-1.webp
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
public/api/i/2025/09/22/nq24rg-1.webp
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
public/api/i/2025/09/22/nq3xj5-1.webp
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
public/api/i/2025/09/22/nqp845-1.webp
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
public/api/i/2025/09/22/nqzx04-1.webp
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
public/api/i/2025/09/22/nr35ne-1.webp
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
public/api/i/2025/09/22/ovqrfw-1.webp
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
public/api/i/2025/09/22/oz4od3-1.webp
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
public/api/i/2025/09/22/p1p5sy-1.webp
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
public/api/i/2025/09/22/p51up4-1.webp
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
public/web/bfg-1.15.0.jar
Normal file
17
src/content/posts/Java/Spring/SpringMVC工作流程.md
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: SpringMVC工作流程
|
||||
published: 2025-09-22
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [SpringMVC,DispatcherServlet]
|
||||
category: 'Java > Spring'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
141
src/content/posts/Java/Spring/Spring中拦截器和过滤器的区别.md
Normal file
@@ -0,0 +1,141 @@
|
||||
---
|
||||
title: Spring中拦截器和过滤器的区别
|
||||
published: 2025-09-22
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [SpringMVC,拦截器,过滤器]
|
||||
category: 'Java > Spring'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
https://www.mianshiya.com/question/1907425766060380162#heading-0
|
||||

|
||||
|
||||
# 过滤器
|
||||
## 实现机制
|
||||
过滤器是Servlet规范的一部分,独立于Spring存在,主要用于过滤请求和响应,可以对所有类型的请求进行处理。
|
||||
## 使用范围
|
||||
可以过滤所有的请求,包括静态资源,jsp,html等,因为它在Servlet容器层面生效。
|
||||
## 配置方法
|
||||
需要实现Filter接口,通过标准的Servlet配置方式进行注册:
|
||||
https://www.cnblogs.com/xfeiyun/p/15790555.html
|
||||
|
||||
https://juejin.cn/post/7000950677409103880
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## 执行顺序
|
||||
先于拦截器执行,因为过滤器作用于Servlet容器层面,拦截器作用在Spring MVC 的处理器映射器找到控制器前或者后执行。
|
||||
|
||||
## 功能侧重
|
||||
侧重于过滤请求和响应的内容,比如设置编码格式,安全控制等。
|
||||
|
||||
# 拦截器
|
||||
## 实现机制
|
||||
拦截器是Spring框架的一部分,基于Java的反射机制实现,主要针对的是Handler的调用
|
||||
|
||||
## 使用范围
|
||||
主要用于拦截访问DispathcherServlet的请求,通常只适用于Spring MVC的应用程序中的请求处理方法。
|
||||
|
||||
|
||||
## 配置方式
|
||||
需要实现org.springframework.web.servlet.HandlerInterceptor接口,并在Spring配置文件中进行注册。
|
||||
可以通过实现WebMvcConfigurer接口的addInterceptors方法来进行注册。
|
||||

|
||||
```java
|
||||
package com.example.interceptor;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @author wipe
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class MyInterceptor1 implements HandlerInterceptor {
|
||||
|
||||
@Override//目标资源方法执行前执行。 返回true:放行 返回false:不放行
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
System.out.println("MyInterceptor1 ... preHandle");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override//目标资源方法执行后执行
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
System.out.println("MyInterceptor1 ... postHandle");
|
||||
}
|
||||
|
||||
@Override//视图渲染完毕后执行,最后执行
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
System.out.println("MyInterceptor1 ... afterCompletion");
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
```java
|
||||
package com.example.config;
|
||||
|
||||
import com.example.filter.MyFilter1;
|
||||
import com.example.filter.MyFilter2;
|
||||
import com.example.interceptor.MyInterceptor1;
|
||||
import com.example.interceptor.MyInterceptor2;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
/**
|
||||
* @author wipe
|
||||
* @version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class MyConfig implements WebMvcConfigurer {
|
||||
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 添加拦截器,并指定执行顺序,也可以通过将拦截器声明成 bean 对象,然后通过 @Order 注解或者实现 Order 接口指定执行顺序
|
||||
registry.addInterceptor(new MyInterceptor1()).order(1);
|
||||
registry.addInterceptor(new MyInterceptor2()).order(2);
|
||||
}
|
||||
|
||||
|
||||
@Bean// 这样配置可以指定过滤器的执行顺序
|
||||
public FilterRegistrationBean<MyFilter1> myFilter1() {
|
||||
FilterRegistrationBean<MyFilter1> filter = new FilterRegistrationBean<>();
|
||||
filter.setFilter(new MyFilter1());
|
||||
filter.addUrlPatterns("/*");
|
||||
filter.setOrder(1);
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<MyFilter2> myFilter2() {
|
||||
FilterRegistrationBean<MyFilter2> filter = new FilterRegistrationBean<>();
|
||||
filter.setFilter(new MyFilter2());
|
||||
filter.addUrlPatterns("/*");
|
||||
filter.setOrder(2);
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
也可以直接用@Component注册Interceptor
|
||||
## 执行顺序
|
||||
可以指定多个拦截器之间的执行顺序,通过实现Ordered接口或者使用@Order注解来控制。
|
||||
|
||||
## 功能侧重
|
||||
侧重于业务逻辑的前置检查,权限验证,日志记录等。
|
||||
16774
src/content/posts/合集/DB.md
Normal file
11390
src/content/posts/合集/Frame.md
Normal file
17608
src/content/posts/合集/Java.md
Normal file
15480
src/content/posts/合集/Prog.md
Normal file
19516
src/content/posts/合集/SSM.md
Normal file
4066
src/content/posts/合集/Tool.md
Normal file
9191
src/content/posts/合集/Web.md
Normal file
164
src/content/posts/工作/Cookie和Session的区别.md
Normal file
@@ -0,0 +1,164 @@
|
||||
---
|
||||
title: Cookie和Session的区别
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [Cookie,Session]
|
||||
category: '工作'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||
# Cookie
|
||||
Cookie是存储在用户浏览器端的一个小型数据文件,用于跟踪和保护用户的状态信息。
|
||||
主要用于保持用户的登录状态,跟踪用户行为,存储用户偏好等。
|
||||
|
||||
**是存储在浏览器的**
|
||||
|
||||
## 为什么需要Cookie
|
||||
HTTP协议是无状态的,意味着每次请求都是独立的,服务器不会记住用户之前的行为。
|
||||
|
||||
用户登录后,服务器无法知道后续请求是否来自同一个用户。
|
||||
|
||||
就像你登录了一个电商网站(如淘宝),假如 HTTP是无状态的,那么你每次刷新页面或跳转到其他页面时,系统都会提示“请重新登录”,这是因为服务器无法记住你之前的登录状态。
|
||||
而通过Cookie,服务器在用户登录成功后设置一个标识。浏览器会将这个标识保存下来,并在后续请求中自动附加到请求头中,服务器通过解析这个标识就能知道用户已登录。
|
||||
|
||||
|
||||
|
||||
浏览器在每次HTTP请求中,自动携带Cookie信息,服务器通过解析这些信息识别用户身份。虽然HTTP协议本身无状态,但通过Cookie的“附加行为”,实现了有状态的交互。
|
||||
## 如何设置Cookie
|
||||
### SpringBoot
|
||||
#### 在 Controller 中设置 Cookie
|
||||
```java
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class CookieController {
|
||||
|
||||
@GetMapping("/set-cookie")
|
||||
public String setCookie(HttpServletResponse response) {
|
||||
Cookie cookie = new Cookie("token", "abc123");
|
||||
cookie.setPath("/"); // 设置路径(整个项目可用)
|
||||
cookie.setMaxAge(60 * 60); // 有效期 1 小时
|
||||
cookie.setHttpOnly(true); // 防止 JS 读取,提升安全性
|
||||
cookie.setSecure(false); // true 代表仅 https 传输
|
||||
response.addCookie(cookie); // 写入响应头
|
||||
|
||||
return "Cookie 已设置!";
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
#### 在 Response Header 中手动写入 Cookie
|
||||
有时需要更细控制,可以直接操作 Set-Cookie 响应头:
|
||||
```java
|
||||
@GetMapping("/set-cookie-header")
|
||||
public String setCookieHeader(HttpServletResponse response) {
|
||||
response.addHeader("Set-Cookie", "sessionId=xyz789; Path=/; HttpOnly; Max-Age=3600");
|
||||
return "Header Cookie 已设置!";
|
||||
}
|
||||
|
||||
```
|
||||
#### 读取 Cookie
|
||||
使用 @CookieValue:
|
||||
```java
|
||||
@GetMapping("/get-cookie")
|
||||
public String getCookie(@CookieValue(value = "token", defaultValue = "null") String token) {
|
||||
return "当前 token = " + token;
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
@GetMapping("/get-cookie2")
|
||||
public String getCookie2(HttpServletRequest request) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie c : cookies) {
|
||||
if ("token".equals(c.getName())) {
|
||||
return "找到 token: " + c.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "未找到 token";
|
||||
}
|
||||
|
||||
```
|
||||
### Cookie组成
|
||||
用户可通过 f12打开控制台,然后应用->Cookie->找到当前地址,就能看到当前的Cookie 信息。
|
||||
|
||||

|
||||
|
||||
- `key=value`: 核心数据
|
||||
- `Set-Cookie`字段: 服务器通过这个字段定义Cookie的内容
|
||||
- `Path=/`: 指定Cookie的而作用路径(/表示所有路径均可访问)
|
||||
- `HttpOnly`: 防止JavaScript 访问Cookie(提高安全性)
|
||||
- `Secure`: 要求Cookie仅能通过HTTPS传输
|
||||
- `Max-Age`: 设置Cookie在多久后过期
|
||||
- `Expires`: 设置Cookie在指定时间过期
|
||||
- `Domain`: 作用域,指定Cookie所属的域名,允许跨子域名共享
|
||||
|
||||
**Max-Age** 和**Expires**是设置Cookie过期时间的两种方式。
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Cookie按照生命周期分为两种
|
||||
会话期cookie是最简单的cookie:浏览器关闭后会被自动删除。会话期cookie不需要指定过期时间(Expires)或者有效期(Max-Age)。需要注意的是,有些浏览器提供了会话恢复功能,这种情况即使关闭了浏览器,会话期cookie也会被保留下来,这会导致cookie的生命周期无限期延长
|
||||
持久性cookie的生命周期取决于过期时间(Expires)或者有效期(Max-Age)指定的一段时间。
|
||||
当Cookie的过期时间被设定时,设定的日期和时间只与客户端相关,而不是服务端。
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Cookie过期时间配置
|
||||
**Max-Age** 和**Expires**是设置Cookie过期时间的两种方式。
|
||||

|
||||

|
||||
|
||||
> 两者都用于设置“持久级 Cookie”(会话级 Cookie 不设置它们)
|
||||
> 同时存在时,Max-Age 优先
|
||||
|
||||
## Cookie大小限制
|
||||
- 单个Cookie最大约为4KB
|
||||
## Cookie数量限制
|
||||
浏览器对同一域名的Cookie数量有限制(如Chrome为200个)
|
||||
## 安全建议:
|
||||
永远不要在Cookie中存储敏感信息(如密码),改用Token或Session ID。
|
||||
始终启用HttpOnly和Secure,防止XSS和中间人攻击。
|
||||
## Cookie优缺点和注意事项
|
||||

|
||||
# Session
|
||||
session是另一种记录客户状态的机制,不同的是Cookie保存在客户端浏览器中,而session保存在服务器上,客户端浏览器访问服务器的时候,服务器把客户端信息以某种形式记录在服务器上,这就是session。客户端浏览器再次访问时只需要从该Session中查找该客户的状态就可以了;
|
||||
## 安全性
|
||||

|
||||
|
||||
|
||||
## Session 的工作流程
|
||||

|
||||
|
||||
## 大小
|
||||
Session是无大小限制的
|
||||
|
||||
|
||||
## 缺陷
|
||||

|
||||

|
||||

|
||||
|
||||
## Cookie和Session的区别
|
||||

|
||||

|
||||
12
src/content/posts/工作/常见开发模型.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: 常见开发模型
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [开发模型,瀑布模型,原型法,V模型,螺旋模型]
|
||||
category: '工作'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||

|
||||
133
src/content/posts/数据结构与算法/排序算法.md
Normal file
@@ -0,0 +1,133 @@
|
||||
---
|
||||
title: 排序算法
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: []
|
||||
category: '数据结构与算法'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||
|
||||
# 冒泡排序
|
||||

|
||||
|
||||
算法复杂度: O(n^2)
|
||||
稳定性: 是稳定排序算法,相等的元素不会变换位置
|
||||
|
||||
```go
|
||||
package main
|
||||
import "fmt"
|
||||
func main() {
|
||||
var n int
|
||||
fmt.Scan(&n)
|
||||
arr := make([]int,n)
|
||||
for i:= range arr {
|
||||
fmt.Scan(&arr[i])
|
||||
}
|
||||
bubbleSort(arr)
|
||||
for i,v := range arr {
|
||||
if i > 0 {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(v)
|
||||
}
|
||||
|
||||
}
|
||||
func bubbleSort(arr []int) {
|
||||
n := len(arr)
|
||||
for i:=0;i<n-1;i++ {
|
||||
for j:=0;j<n-1-i;j++ {
|
||||
if arr[j] > arr[j + 1] {
|
||||
arr[j],arr[j + 1] = arr[j + 1],arr[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
```java
|
||||
import java.util.Scanner;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int n = sc.nextInt();
|
||||
int[] arr = new int[n];
|
||||
for(int i = 0;i<n;i++) {
|
||||
arr[i] = sc.nextInt();
|
||||
}
|
||||
bubbleSort(arr);
|
||||
for(int i = 0;i<n;i++) {
|
||||
System.out.print(arr[i] + " ");
|
||||
}
|
||||
|
||||
}
|
||||
static void bubbleSort(int[] arr) {
|
||||
int n = arr.length;
|
||||
for(int i = 0;i<n - 1;i++) {
|
||||
for(int j = 0;j<n - 1 - i;j++) {
|
||||
int temp = arr[j];
|
||||
if(arr[j + 1] < arr[j]) {
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
# 快速排序
|
||||
## 时间复杂度
|
||||
平均时间复杂度: O(nlogn)
|
||||
最坏时间复杂度: O(n^2) 在已经排序或者大部分已排序的情况下
|
||||
最好时间复杂度: O(nlogn)
|
||||
## 空间复杂度
|
||||
是原地排序,只占用少量的额外空间,空间复杂度是O(logn),主要是递归调用栈的空间
|
||||
## 稳定性
|
||||
快速排序是 不稳定 排序。
|
||||
|
||||
采用分治策略排列元素,把数组分成两个子数组,递归排序,再合并。
|
||||
|
||||
分区的基本思想
|
||||
分区的目标:选择一个基准元素(pivot),将数组重新排列,使得:
|
||||
## 分区思想
|
||||
基准左边的所有元素 <= 基准
|
||||
基准右边的所有元素 >= 基准
|
||||
基准本身位于最终的正确位置
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
func main() {
|
||||
var n int
|
||||
fmt.Scan(&n)
|
||||
arr := make([]int,n)
|
||||
for i:= range arr {
|
||||
fmt.Scan(&arr[i])
|
||||
}
|
||||
quickSort(arr,0,len(arr) - 1)
|
||||
}
|
||||
func quickSort(arr []int,low int,high int) {
|
||||
if low < high {
|
||||
pi := partition(arr,low,high)
|
||||
quickSort(arr,low,pi - 1)
|
||||
quickSort(arr,pi + 1,high)
|
||||
}
|
||||
}
|
||||
func partition(arr []int,low int,high int) int {
|
||||
pivot := arr[high]
|
||||
i := low - 1
|
||||
for j := low;j < high;j++ {
|
||||
if arr[j] <= pivot {
|
||||
i++
|
||||
arr[i],arr[j] = arr[j],arr[i]
|
||||
}
|
||||
}
|
||||
arr[i + 1],arr[high] = arr[high],arr[i + 1]
|
||||
return i + 1
|
||||
}
|
||||
```
|
||||
31
src/content/posts/解决方案/Git不小心提交了100M以上文件导致无法提交解决方案.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: Git不小心提交了100M以上文件导致无法提交解决方案
|
||||
published: 2025-09-20
|
||||
description: ''
|
||||
image: ''
|
||||
tags: []
|
||||
category: '疑难杂症'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
可以直接用这个Scala写的bfg,点击下载:
|
||||
https://blog.meowrain.cn/web/bfg-1.15.0.jar
|
||||
|
||||
https://github.com/rtyley/bfg-repo-cleaner
|
||||
|
||||
文档: https://rtyley.github.io/bfg-repo-cleaner/
|
||||
|
||||

|
||||
|
||||

|
||||
36
src/content/posts/计算机网络/HTTP中GET和POST的区别是什么.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: HTTP中GET和POST的区别是什么
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [计算机网络,HTTP]
|
||||
category: '计算机网络'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||
# HTTP中GET和POST的区别是什么
|
||||
## 从HTTP定义看
|
||||
从HTTP定义看
|
||||
GET用来获取资源。通常用来请求数据,不改变服务器状态
|
||||
POST用来提交数据到服务器,通常会改变服务器状态或者产生副作用(比如创建或者更新资源)
|
||||
|
||||
## 参数传递
|
||||
GET是通过URL拼接来实现参数传递的,暴露在请求URL中,有可见性,长度有限。(2048字节)
|
||||
POST把参数放在请求体里面,通常不可见而且长度理论上也没有限制,更适合传递大量数据(nginx默认限制为1M)。
|
||||
|
||||
## 安全性
|
||||
GET: 参数可见,数据容易暴露在浏览器历史记录,日志和缓存中,不适合传递敏感信息。
|
||||
POST: 数据放在请求体中,相对安全,但需要HTTPS才能保证数据加密传输。
|
||||
|
||||
## 幂等性
|
||||
GET: 幂等的(重复请求不会改变服务器状态)
|
||||
POST: 非幂等的(多次请求可能导致重复创建资源或者执行多次相同的操作)
|
||||
|
||||
|
||||
## RESTful API设计中的角色分工
|
||||
- GET 用来查询或者检索资源数据
|
||||
- POST: 用来创建资源或者执行某些动作
|
||||
- PUT和PATCH: 用来更新资源 PUT替换整个资源,PATCH更新部分资源
|
||||
- DELETE: 用来删除资源。
|
||||
|
||||
32
src/content/posts/计算机网络/HTTP请求中包含哪些内容请求头和请求体有哪些内容.md
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: HTTP请求中包含哪些内容请求头和请求体有哪些内容
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [HTTP,计算机网络,请求头,请求体]
|
||||
category: '计算机网络'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||
# HTTP请求由以下几部分组成:
|
||||
- 请求行(请求方法,请求资源路径,HTTP协议版本)
|
||||
- 请求头
|
||||
- 空行
|
||||
- 请求体
|
||||
|
||||
# 常见请求头与请求体
|
||||

|
||||
|
||||
|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
# URI URL URN
|
||||
URI
|
||||
├─ URL(通过“位置+协议”定位资源)
|
||||
└─ URN(通过“唯一名称”标识资源,与位置无关)
|
||||
22
src/content/posts/计算机网络/TCP四层模型.md
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: TCP/IP 四层模型
|
||||
published: 2025-09-22
|
||||
description: ''
|
||||
image: ''
|
||||
tags: []
|
||||
category: '计算机网络'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||

|
||||
|
||||
# TCP/IP 四层模型
|
||||
|
||||
TCP/IP 四层模型是一个分层网络通信模型,将网络通信过程分为四个层次,这四层分别是:
|
||||
- 网络接口层 以太网,WIFI,PPP
|
||||
- 网络层 IP,ICMP,ARP
|
||||
- 传输层 TCP,UDP
|
||||
- 应用层 HTTP,FTP,SMTP
|
||||

|
||||
|
||||
|
||||
28
src/content/posts/计算机网络/常见HTTP状态码.md
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: 常见HTTP状态码
|
||||
published: 2025-09-21
|
||||
description: ''
|
||||
image: ''
|
||||
tags: [HTTP,状态码,计算机网络]
|
||||
category: '计算机网络'
|
||||
draft: false
|
||||
lang: ''
|
||||
---
|
||||
|
||||
# 1xx信息响应
|
||||
- 100 Continue: 服务器已接收请求的初步部分,客户端应该继续请求
|
||||
- 101 Switching Protocols: 服务器同意切换协议,比如从HTTP切换到Webscoket
|
||||
|
||||
# 2xx信息响应
|
||||
- 200 OK: 请求成功,服务器返回请求的资源或者数据
|
||||
- 201 Created: 请求成功并创建了新资源,常用于POST请求
|
||||
- 204 No Content: 请求成功但服务器不返回任何信息,常用于删除操作
|
||||
|
||||
# 3xx 重定向
|
||||
- 301 Moved Permanently: 资源已永久移动到新的URL,客户端应该用新URL访问。
|
||||
- 302 Found: 资源临时移动到新的URL,客户端应该继续使用原来的URL
|
||||
|
||||
## 常见重定向机制
|
||||

|
||||
|
||||
|
||||