springboot+vue3项目搭建时经常用到的类

模板下载:https://img-hepingan.oss-cn-hangzhou.aliyuncs.com/muban.zip

SpringBoot

Controller层注解

1
2
3
4
5
@CrossOrigin(origins = {"*", "null"})
@RequestMapping("/emp")
@RestController
@Slf4j
@RequiredArgsConstructor

Do类注解例

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
@Data
@TableName(value = "user")
@Accessors(chain = true)
public class User {
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Long user_id;

private String name;

private String phone;

private Long frequency;

private Long isVip;

/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createdTime;

/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}

字符串处理类

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
package top.hepingan.utils;

import java.util.List;
import java.util.Objects;

/**
* 字符串处理类
*
* @author @github dulaiduwang003
* @version 1.0
*/
@SuppressWarnings("all")
public final class StringUtils extends org.apache.commons.lang3.StringUtils {


public static boolean isLegal(String str) {
if (isEmpty(str)) {
return true;
}
return !str.contains("|");
}

public static boolean notEmpty(String str) {
if (Objects.nonNull(str) && str.length() > 0) {
return true;
}

return false;
}


public static <T> String join(List<T> list) {
return join(list.toArray());
}


public static <T> String join(List<T> list, String separator) {
return join(list.toArray(), separator);
}

}

Redis信息类

要搭配下面的Redis配置类一起使用

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package top.hepingan.utils;

import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;


/**
* redis工具类
*
* @author @github dulaiduwang003
* @version 1.0
*/
@Component
@SuppressWarnings("all")
@RequiredArgsConstructor
public final class RedisUtils {

private final RedisTemplate<String, Object> redisTemplate;

public RedisTemplate getRedisTemplate() {
return this.redisTemplate;
}


public boolean expire(final String key, final long timeout) {
return expire(key, timeout, TimeUnit.SECONDS);
}

public Long getExpire(final String key) {
return redisTemplate.getExpire(key);
}


public boolean expire(final String key, final long timeout, final TimeUnit unit) {
Boolean ret = redisTemplate.expire(key, timeout, unit);
return ret != null && ret;
}

public boolean hasKey(final String key) {
return redisTemplate.hasKey(key);
}

public long increment(final String key, final long delta) {
return redisTemplate.opsForValue().increment(key, delta);
}

public boolean delKey(final String key) {
Boolean ret = redisTemplate.delete(key);
return ret != null && ret;
}


public long delKeys(final Collection<String> keys) {
Long ret = redisTemplate.delete(keys);
return ret == null ? 0 : ret;
}


public void setValue(final String key, final Object value) {
redisTemplate.opsForValue().set(key, value);
}


public void setValueTimeout(final String key, final Object value, final long timeout) {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
}


public Object getValue(final String key) {
return redisTemplate.opsForValue().get(key);
}


public boolean hasHashKey(final String key, String hkey) {
Boolean ret = redisTemplate.opsForHash().hasKey(key, hkey);
return ret != null && ret;
}


public void hashPut(final String key, final String hKey, final Object value) {
redisTemplate.opsForHash().put(key, hKey, value);
}


public void hashPutAll(final String key, final Map<String, Object> values) {
redisTemplate.opsForHash().putAll(key, values);
}


public Object hashGet(final String key, final String hKey) {
return redisTemplate.opsForHash().get(key, hKey);
}


public Map<Object, Object> hashGetAll(final String key) {
return redisTemplate.opsForHash().entries(key);
}


public List<Object> hashMultiGet(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(key, hKeys);
}

public boolean hashExists(String key, String hashKey) {
return redisTemplate.opsForHash().hasKey(key, hashKey);
}


public long hashDeleteKeys(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().delete(key, hKeys);
}

public Long hashDelete(final String key, final Object... hashKey) {
return redisTemplate.opsForHash().delete(key, hashKey);
}


public long setSet(final String key, final Object... values) {
Long count = redisTemplate.opsForSet().add(key, values);
return count == null ? 0 : count;
}


public long setDel(final String key, final Object... values) {
Long count = redisTemplate.opsForSet().remove(key, values);
return count == null ? 0 : count;
}


public Set<Object> getSetAll(final String key) {
return redisTemplate.opsForSet().members(key);
}


public long zsetSetAll(final String key, final Set<ZSetOperations.TypedTuple<Object>> values) {
Long count = redisTemplate.opsForZSet().add(key, values);
return count == null ? 0 : count;
}

public Double zsetSetGetSource(final String key, final Object value) {


return redisTemplate.opsForZSet().score(key, value);
}

public Double zsetIncrementScore(final String key, final Object value, final Double increment) {
return redisTemplate.opsForZSet().incrementScore(key, value, increment);
}

public Boolean zsetSet(final String key, final Object values, final Double source) {
final Boolean add = redisTemplate.opsForZSet().add(key, values, source);
return add;
}


public Set<ZSetOperations.TypedTuple<Object>> zsetReverseRangeWithScores(final String key, final Long start, final Long end) {
return redisTemplate.opsForZSet().reverseRangeWithScores(key, start, end);
}


public Set<Object> zsetReverseRange(final String key, final Long start, final Long end) {
return redisTemplate.opsForZSet().reverseRange(key, start, end);
}


public long selfIncrease(final String key) {
return redisTemplate.execute(new SessionCallback<Long>() {
@Override
public Long execute(RedisOperations operations) throws DataAccessException {
operations.multi();
Long count = operations.opsForValue().increment(key);
operations.exec();
return count;
}
});
}

public Double selfIncreaseSource(final String key, final Object value) {
return redisTemplate.execute(new SessionCallback<Double>() {
@Override
public Double execute(RedisOperations operations) throws DataAccessException {
operations.multi();
Double count = operations.opsForZSet().incrementScore(key, value, 1);
operations.exec();
return count;
}
});
}

public long zsetDelAll(final String key, final Set<ZSetOperations.TypedTuple<Object>> values) {
Long count = redisTemplate.opsForZSet().remove(key, values);
return count == null ? 0 : count;
}

public long zsetDel(final String key, Object values) {
Long count = redisTemplate.opsForZSet().remove(key, values);
return count == null ? 0 : count;
}

public long listPush(final String key, final Object value) {
Long count = redisTemplate.opsForList().rightPush(key, value);
return count == null ? 0 : count;
}

public Boolean doesItExist(final String key) {
return redisTemplate.hasKey(key);
}

public long listPushAll(final String key, final Collection<Object> values) {
Long count = redisTemplate.opsForList().rightPushAll(key, values);
return count == null ? 0 : count;
}

public long listPushAll(final String key, final Object... values) {
Long count = redisTemplate.opsForList().rightPushAll(key, values);
return count == null ? 0 : count;
}


public List<Object> listGet(final String key, final int start, final int end) {
return redisTemplate.opsForList().range(key, start, end);
}

public Long keySize(final String key) {
return redisTemplate.opsForList().size(key);
}
}

Redis配置类

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
104
105
106
107
108
109
110
111
112
113
114
package top.hepingan.config;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


/**
* Redis参数配置
*
* @author @github dulaiduwang003
* @version 1.0
*/
@Configuration
@SuppressWarnings("all")
@AutoConfigureBefore(RedisAutoConfiguration.class)
public class RedisConfig {

@Bean
public Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer() {
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
om.registerModule(timeModule());
serializer.setObjectMapper(om);
return serializer;
}

@Bean
public StringRedisSerializer stringRedisSerializer() {
return new StringRedisSerializer();
}


@Bean
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory,
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer,
StringRedisSerializer stringRedisSerializer) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(lettuceConnectionFactory);
template.setKeySerializer(stringRedisSerializer);
template.setHashKeySerializer(stringRedisSerializer);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}


@Bean
public RedisCacheConfiguration redisCacheConfiguration(Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer,
RedisSerializer<String> redisSerializer) {
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofSeconds(3600 * 24 * 10))
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
.disableCachingNullValues();
}

@Bean
public CacheManager cacheManager(RedisConnectionFactory factory,
RedisSerializer<String> redisSerializer,
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer,
RedisCacheConfiguration redisCacheConfiguration) {
RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
.cacheDefaults(redisCacheConfiguration)
.build();
return cacheManager;
}

@Bean
public JavaTimeModule timeModule() {
JavaTimeModule timeModule = new JavaTimeModule();
timeModule.addDeserializer(LocalDate.class,
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
timeModule.addDeserializer(LocalDateTime.class,
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
timeModule.addSerializer(LocalDate.class,
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
timeModule.addSerializer(LocalDateTime.class,
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
return timeModule;
}


}

Bean处理类

(很少用)

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
package top.hepingan.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.List;


/**
* @author @github dulaiduwang003
* @version 1.0
*/
public final class BeanUtils {

public static <S, T> T copyClassProperTies(S source, Class<T> target) {
return JSON.parseObject(JSON.toJSONString(source), target);
}

public static <T> List<T> copyArrayProperTies(Object source, Class<T> target) {
return JSON.parseArray(JSON.toJSONString(source), target);
}


public static <S, T> T copyClassProperTiesWriteDate(S source, Class<T> target) {
return JSON.parseObject(
JSONObject.toJSONStringWithDateFormat(source, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat), target
);

}


/**
* Copy array proper ties write date list.
*
* @param <T> the type parameter
* @param source the source
* @param target the target
* @return the list
*/
public static <T> List<T> copyArrayProperTiesWriteDate(Object source, Class<T> target) {
return JSON.parseArray(
JSONObject.toJSONStringWithDateFormat(source, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat), target
);
}
}

yml配置

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
spring:
codec:
max-in-memory-size: 1048576
servlet:
multipart:
max-file-size: 10240MB
max-request-size: 10240MB
application:
name: H_Java
data:
# redis??
redis:
timeout: 10s
lettuce:
pool:
max-active: 200
max-wait: -1ms
max-idle: 10
min-idle: 1
database: 2
host: 127.0.0.1
port: 6379
password: 'xxxxx'
# mysql??
datasource:
url: jdbc:mysql://127.0.0.1:3306/h?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true&useSSL=true
username: root
password: xxxxx
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver

sa-token:
token-name: token
active-timeout: -1
is-concurrent: true
is-share: false
is-log: false
# token ?????????uuid?simple-uuid?random-32?random-64?random-128?tik?
token-style: uuid

server:
port: 8601

mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
cache-enabled: false
jdbc-type-for-null: 'null'

# 阿里OSS
ali-oss:
endpoint: 'oss-cn-hangzhou.aliyuncs.com'
accessKey: ''
secretKey: ''
bucketName: ''
domain: ''

Result前后端返回类

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package top.hepingan.model;

import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

public class Result extends LinkedHashMap<String, Object> implements Serializable {


private static final long serialVersionUID = 1L;

public static final int CODE_SUCCESS = 200;

public static final int CODE_ERROR = 500;


public Result() {
}

public Result(int code, String msg, Object data) {
this.setCode(code);
this.setMsg(msg);
this.setData(data);
}


public Result(Map<String, ?> map) {
this.setMap(map);
}

public Integer getCode() {
return (Integer) this.get("code");
}

public String getMsg() {
return (String) this.get("msg");
}


public Object getData() {
return this.get("data");
}


public Result setCode(int code) {
this.put("code", code);
return this;
}


public Result setMsg(String msg) {
this.put("msg", msg);
return this;
}


public Result setData(Object data) {
this.put("data", data);
return this;
}

public Result set(String key, Object data) {
this.put(key, data);
return this;
}


public Result setMap(Map<String, ?> map) {
Iterator var2 = map.keySet().iterator();

while (var2.hasNext()) {
String key = (String) var2.next();
this.put(key, map.get(key));
}

return this;
}

public static Result ok() {
return new Result(CODE_SUCCESS, "操作成功", (Object) null);
}


public static Result ok(String msg) {
return new Result(CODE_SUCCESS, msg, (Object) null);
}


public static Result code(int code) {
return new Result(code, (String) null, (Object) null);
}


public static Result data(Object data) {
return new Result(CODE_SUCCESS, "ok", data);
}


public static Result error() {
return new Result(CODE_ERROR, "操作失败", (Object) null);
}


public static Result error(final String msg, final Integer code) {
return new Result(code, msg, (Object) null);
}


public static Result error(String msg) {
return new Result(CODE_ERROR, msg, (Object) null);
}

public static Result error(String msg, int code) {
return new Result(code, msg, (Object) null);
}


public static Result build(int code, String msg, Object data) {
return new Result(code, msg, data);
}


public String toString() {
return "{\"code\": " + this.getCode() + ", \"msg\": " + this.transValue(this.getMsg()) + ", \"data\": " + this.transValue(this.getData()) + "}";
}


private String transValue(Object value) {
return value instanceof String ? "\"" + value + "\"" : String.valueOf(value);
}
}


一般springboot流行maven配置类,即pom.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?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>3.1.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>top.hepingan</groupId>
<artifactId>H_Java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>H_Java</name>
<description>H_Java</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>cn.ipokerface</groupId>
<artifactId>snowflake-id-generator</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.20.1</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.35.107.ALL</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.32</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.nanohttpd</groupId>
<artifactId>nanohttpd-websocket</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.35</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>cn.ipokerface</groupId>
<artifactId>snowflake-id-generator</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
<version>1.35.0.RC</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
<version>1.35.0.RC</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>



<!-- <dependency>-->
<!-- <groupId>com.google.code.gson</groupId>-->
<!-- <artifactId>gson</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpclient</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>

VUE

一般vue3项目目录预览:

main.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { createApp } from 'vue'
import App from './App.vue'
import router from "@/router";
import ElementPlus from 'element-plus';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/theme-chalk/index.css';
import 'element-plus/theme-chalk/display.css';


let app = createApp(App)
app.use(router)
app.use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.mount('#app')

router.js

routes里一个花括号就是一个路由

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
import {createRouter, createWebHashHistory} from 'vue-router'
import {cancelArr} from "@/utils/BSideRequest";

const routes = [{
path: '/',
name: 'Index',
component: () => import('../views/EmployeeView.vue'),
},{
path: '/user',
name: 'UserView',
component: ()=>import('../views/UserView.vue'),
}]

const router = createRouter({
history: createWebHashHistory(),
routes
})


// TODO 全局前置守卫
router.beforeEach(async (to) => {
// TODO 页面切换中断所有请求
cancelArr.forEach((cancel, index) => {
cancel()
cancelArr.splice(index, 1)
})

// TODO 设置浏览器Title
document.title = (to.meta.title ? to.meta.title : '') + ' - H公司管理系统'
})

export default router

BSideRequest.js

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
import axios from 'axios'

// TODO 请求取消令牌列表
export let cancelArr = [];

// TODO 创建axios实例
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 6 * 60 * 1000
});

// TODO 请求拦截器
service.interceptors.request.use(config => {
// TODO 请求头
config.headers['token'] = localStorage.getItem('token')

// TODO 添加取消令牌
config.cancelToken = new axios.CancelToken(cancel => {
cancelArr.push(cancel)
})

return config
}, error => {
return Promise.reject(error)
});

// TODO 响应拦截器
service.interceptors.response.use(response => {
const res = response.data;
if (res.code !== 200) {
if (res.code === 401) {
localStorage.removeItem('token');
localStorage.removeItem('user');
location.reload();
} else {
throw res.msg
}
} else {
return res.data
}
}, () => {
throw '服务调用失败,正在紧急处理,请稍后使用。'
})

export default service

环境配置.env.development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# just a flag
ENV = 'development'

# HTTP请求基类
VUE_APP_BASE_API = 'http://localhost:8601'

# 长连接基类
VUE_APP_WSS = 'ws://localhost:8601'

# 图片服务器域名
VUE_APP_IMAGE = 'https://img-hepingan.oss-cn-hangzhou.aliyuncs.com'

VUE_APP_RATE = 20

VUE_APP_MEMORY = 4

VUE_APP_MEMORY_SIZE = 2000

BSideApi.js格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import request from '@/utils/BSideRequest'
export function GetSdModelPage(pageNum,prompt) {
return request({
url: 'emp/get/page?pageNum='+ pageNum +'&prompt='+ prompt,
method: 'GET'
})
}

export function GetEmployeeList() {
return request({
url: 'emp/get/emp',
method: 'GET'
})
}

我的vue项目里有的库:

1
2
3
4
5
6
7
8
9
10
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"axios": "^1.7.2",
"core-js": "^3.6.5",
"element-plus": "^2.7.7",
"v-md-editor": "^1.0.6",
"vue": "^3.0.0",
"vue-router": "^4.4.0",
"vuex": "^4.1.0"
},

即axios,element-plus,v-md-editor,vuex,vue-router,推荐安装不然上面有些用不了

css库推荐:Tailwind CSS - 只需书写 HTML 代码,无需书写 CSS,即可快速构建美观的网站。 | TailwindCSS中文文档 | TailwindCSS中文网

maven仓库:Maven Repository: Search/Browse/Explore (mvnrepository.com)

redis教程:Window下Redis的安装和部署详细图文教程(Redis的安装和可视化工具的使用)_redis安装-CSDN博客

element-plus:一个 Vue 3 UI 框架 | Element Plus (element-plus.org)