有料

Windows下端口占用问题解决

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 查看端口
netstat -ano

# 查询指定端口
netstat -ano | findstr "端口号"

# 根据进程pid查询进程名称
netstat |findstr "进程pid"

# 根据pid杀死任务
taskkill /f /pid "进程pid"

# 根据进程名杀死任务
taskkill -f -t -im "进程名称"

Spring核心配置文件的模板

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

Docker命令图

Docker命令图


Dockerfile文件格式

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 基础镜像,tag不写默认为latest
# 只能写一次
FROM <image>
FROM <image>:<tag>
# example
# FROM centos

# 作者信息name一般为邮箱
MAINTAINER <name>
# example
# MAINTAINER zhima<1158778689@qq.com>

# 设置镜像的元数据标签信息
LABEL <info>
# example
# LABEL version="1.0"
# LABEL description="this is description"

# 设置环境变量
ENV <key> <value>
ENV <key>=<value> <key>=<value> ...
# example
# ENV DIRPATH /path

# 设置运行RUN CMD ENTRYPOINT的用户名
USER <userName>
USER <UID>

# 设置工作目录
# 对RUN,CMD,ENTRYPOINT,COPY,ADD生效
# 如果不存在则会创建
WORKDIR 镜像内地址
# example
# 使用$读取环境变量
# WORKDIR $DIRPATH

# 定义变量
# 在docker build创建镜像的时候,使用 --build-arg <varname>=<value>来指定参数
ARG <name>[=<default value>]

# 为子镜像设置命令
# 当本镜像作为其他容器的基础镜像的时候,INSTRUCTION会在子镜像运行的时候执行
ONBUILD [INSTRUCTION]
# example
# ONBUILD RUN ls -al

# 添加文件到镜像
# source可写
# 宿主机的绝对路径
# 本Dockerfile所在目录的相对路径
# url,如果使用url,则此ADD相当于wget
# source如果是压缩包,则会自动解压
ADD <source> <dest>

# 复制文件到镜像中
# COPY的<source>只能是本地文件,其他用法与ADD一致
COPY <source> <dest>

# 在**构建**镜像的时候运行的命令,一般是安装命令
RUN <command>
RUN ["executable","param1"]
# example
# RUN yum install -y gcc
# 下面三行RUN命令是为了解决以下这个错误的
# Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
# RUN cd /etc/yum.repos.d/
# RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

# 暴露容器运行时的监听端口给外部
EXPOSE <port>
# 但是EXPOSE并不会使容器访问主机的端口
# 如果想使得容器与主机的端口有映射关系,必须在容器启动的时候加上 -p参数

# 数据卷
# 这种是匿名数据卷 宿主机会在/var/lib/docker/volumes下生成一个随机命名的目录
# 可以在运行容器的时候,指定挂载卷的名字
# -v 卷名:镜像内想要被挂载的地址2
VOLUME ["镜像内想要被挂载的地址1","镜像内想要被挂载的地址2"]
VOLUME "镜像内想要被挂载的地址1" "镜像内想要被挂载的地址2"

# 容器**运行**的时候运行的命令
CMD <command>
CMD ["executable","param1"]
# example
# CMD ["cd","/usr/local"]
# CMD cd /usr/local

# 容器运行的时候运行的命令
ENTRYPOINT java -jar demo.jar
ENTRYPOINT ["java","-jar","demo.jar"]
# ENTRYPOINT和CMD的区别
# 不同之处
# 1.ENTRYPOINT不会被运行的command覆盖,而CMD则会被覆盖
# 2.如果我们在Dockerfile种同时写了ENTRYPOINT和CMD
# 并且CMD指令不是一个完整的可执行命令,那么CMD指定的内容将会作为ENTRYPOINT的参数
# 3.docker run image <参数>
# 传入的参数会追加在ENTRYPOINT之后
# 如果是CMD,会直接覆盖此CMD
# 相同之处
# 只能写一条,如果写了多条,那么只有最后一条生效
# 容器启动时才运行
# 如果我们在Dockerfile种同时写了ENTRYPOINT和完整的CMD,ENTRYPOINT一定会执行,CMD不会执行

Docker-compose格式

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 指定compose版本,一般3.1就可以了
version: '3.1'

# 服务列表
services:
# 自定义服务名
service_name1:
# 使用docker build构建镜像
# Dockerfile的地址
build:
context: .
dockerfile: custom-Dockerfile
# 如果dockerfile文件名就叫Dockerfile,则可以使用简写模式
# build: .

# 如果有build则是指定构建出来的镜像的镜像名
# 如果没有build则是指定运行的镜像
image: <imageName>:<tag>
# 指定运行容器的名称
container_name: <container_name>
# 容器卷技术
volumes:
- /usr/local/mysql # 匿名挂载
- VolumeName:/home/zhima #具名挂载
- /temp/mysql/config:/etc/mysql/conf.d # 宿主机挂载
# 端口映射
ports:
- "宿主机端口:容器端口"
# 运行容器的时候的参数
command: [
"param1",
"param2"
]
# 指定加入的网络
networks:
- network1
- network2
# 第二个服务
service_name2:
# 使用构建好的镜像
image: <imageName>:<tag>
stdin_open: true # 类似于docker run -d
tty: true # 类似于docker run -t
depends_on:
- service_name1
networks:
network1:
driver: bridge
network2:
driver: bridge

Git命令图

Git常用命令图


SpringMVC的web.xml模板

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
32
33
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

数据库模板配置文件

1
2
3
spring.datasource.url=jdbc:mysql://locoalhost:3306/dbname?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456

MyBatis配置文件的模板

核心配置文件

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>

映射器xml文件

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youkeda.comment.dao.UserDAO">

</mapper>

druid连接池配置文件

maven坐标

1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>

一部分核心配置文件

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
32
33
34
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/dbName?serverTimezone=UTC&useUnicodestrue&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
#Spring Boot 默认是不注入这些属性值的,需要自己绑定
#druid druid特有配置
druid:
initialSize: 5
minIdle: 5
maxActive: 20
maxwait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
#配置监控统计栏截的filters,stat: 监控统计、Log4j: 日志记录、wall: 防御sqL注入
#如果允许时报借 java.Lang.CLassNotFoundException: org.apache.Log4j.Priority
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourcestat: true
connectionProperties: druid.stat.mergesqletrue;druid.stat.slowSq1Millis=500
stat-view-servlet:
enabled: true
url-pattern: /druid/*
login-password: admin
login-username: 123456
allow:
deny:

后台监控页面也可以通过以下方式配置

1
2
3
4
5
6
7
8
9
10
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean<Servlet> bean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*");
Map<String, String> params = new HashMap<>();
params.put("loginUserName","admin");
params.put("loginPassword","123456");
params.put("allow","localhost");
bean.setInitParameters(params);
return bean;
}

去除druid的广告

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.lizhi.springbootdata;


import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.servlet.*;
import java.io.IOException;

@Configuration
@ConditionalOnWebApplication
@AutoConfigureAfter(DruidDataSourceAutoConfigure.class)
@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true", matchIfMissing = true)
public class RemoveDruidAdConfig {
/**
* 方法名: removeDruidAdFilterRegistrationBean
* 方法描述: 除去页面底部的广告
* @param properties
* @return org.springframework.boot.web.servlet.FilterRegistrationBean
* @throws
*/
@Bean
public FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties) {
// 获取web监控页面的参数
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// 提取common.js的配置路径
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");

final String filePath = "support/http/resources/js/common.js";

//创建filter进行过滤
Filter filter = new Filter() {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
// 重置缓冲区,响应头不会被重置
response.resetBuffer();
// 获取common.js
String text = Utils.readFromResource(filePath);
// 正则替换banner, 除去底部的广告信息
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
text = text.replaceAll("powered.*?shrek.wang</a>", "");
response.getWriter().write(text);
}

@Override
public void destroy() {
}
};
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(filter);
registrationBean.addUrlPatterns(commonJsPattern);
return registrationBean;
}
}

GitHub

加速

https://gitee.com/docmirror/dev-sidecar?_from=gitee_search

高质量项目

https://github.com/kon9chunkit/Github-Chinese-Top-Charts#%E7%9B%AE%E5%BD%95

官方文档

https://docs.github.com/cn


maven中资源导出出现问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!--在build中配置resources,来防止我们资源导出出现的问题-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>

CORS跨域请求的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowCredentials(true)
.allowedOriginPatterns("*")
.maxAge(2000);
}
}
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
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsConfig1 {
private static final long MAX_AGE=24*60*60;

private CorsConfiguration buildConfig(){
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setMaxAge(MAX_AGE);
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**",buildConfig());
return new CorsFilter(source);
}
}

SpringSession的配置

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
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

import java.util.concurrent.ConcurrentHashMap;

@Configuration
@EnableSpringHttpSession
public class SpringHttpSessionConfig {
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("JSESSIONID");
// 用正则表达式配置匹配的域名,可以兼容 localhost、127.0.0.1 等各种场景
serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
serializer.setCookiePath("/");
serializer.setUseHttpOnlyCookie(false);
// 最大生命周期的单位是秒
serializer.setCookieMaxAge(48 * 60 * 60);
return serializer;
}

@Bean
public MapSessionRepository sessionRepository() {
return new MapSessionRepository(new ConcurrentHashMap<>());
}
}

Log4j 核心配置文件

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
#将等级为DEBUG的志信息输出到console和file这两个目的地。console和file的定义在下面的代码
log4j.rootLogger=DEBUG,console,file

#范制台偷出的相关设置
log4j.appender.console =org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.Threshold=DEBUg
log4j.appender.console.layout =org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%c]-%m%n

#文件输出的相关设置
log4j.appender.file =org.apache.log4j.RollingFileAppender
#日志文件输出的磁盘路径
log4j.appender.file.File=./log/lizhi.log
log4j.appender.file.MaxFileSize=10mb
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#日去输出级别
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.Preparedstatement=DEBUG

字体图标的使用

使用字体图标前,添加字体申明,参考如下或者直接在style.css文件中复制

1
2
3
4
5
6
7
8
9
10
11
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?suef9x');
src: url('fonts/icomoon.eot?suef9x#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?suef9x') format('truetype'),
url('fonts/icomoon.woff?suef9x') format('woff'),
url('fonts/icomoon.svg?suef9x#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}

记得修改字体(font-family)为icomoon

更新服务器时间

1
2
3
4
5
[root@localhost ~]# date -R
Fri, 27 Jan 2023 00:23:13 +0800
[root@localhost /]# yum install -y ntp
[root@localhost /]# date -R
Sat, 28 Jan 2023 15:27:20 +0800