Skip to content

Commit 06c7749

Browse files
author
litongjava
committed
add dependenies to tio-boot file upload and download demo
1 parent 919423c commit 06c7749

File tree

3 files changed

+170
-25
lines changed

3 files changed

+170
-25
lines changed

docs/zh/99_案例/01.md

+68-23
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
tio-boot-生产级别案例-用户登录和注册
2-
本章节使用tio-boot开发一个用户注册和登录系统
3-
首先会在mysql中创建一张表
4-
然后使用jfinal-plugins连接mysql
5-
使用sa-token将用户信息保存到reids
1+
# tio-boot-案例-用户登录和注册
2+
3+
本章节使用 tio-boot 开发一个用户注册和登录系统
4+
首先会在 mysql 中创建一张表
5+
然后使用 jfinal-plugins 连接 mysql
6+
使用 sa-token 将用户信息保存到 reids
67
1.1.创建表
8+
79
```
810
CREATE TABLE IF NOT EXISTS `sys_user_info` (
911
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
@@ -130,15 +132,19 @@ CREATE TABLE IF NOT EXISTS `sys_user_info` (
130132
</dependency>
131133
</dependencies>
132134
```
135+
133136
1.3.配置文件
134137
app.properties
138+
135139
```
136140
server.port=9204
137141
server.context-path=/pen-api
138142
# 或 prod
139143
app.env=dev
140144
```
145+
141146
app-dev.properties
147+
142148
```
143149
jdbc.url=jdbc:mysql://192.168.3.9/enote?characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC
144150
jdbc.user=root
@@ -153,6 +159,7 @@ redis.timeout=15000
153159
```
154160

155161
i18n_en_US.properties
162+
156163
```
157164
The_username_or_password_cannot_be_empty=The username or password cannot be empty
158165
The_locale_cannot_be_empty=The locale cannot be empty
@@ -166,7 +173,9 @@ The_password_should_contain_uppercase_letters,_lowercase_letters_and_numbers=The
166173
The_locale_at_least_5_characters=The locale at least 5 characters
167174
The_username_exists=The username exists
168175
```
176+
169177
i18n_zh_CN.properties
178+
170179
```
171180
The_username_or_password_cannot_be_empty=用户名或者密码不能为空
172181
The_locale_cannot_be_empty=locale不能为空
@@ -180,7 +189,9 @@ The_password_should_contain_uppercase_letters,_lowercase_letters_and_numbers=pas
180189
The_locale_at_least_5_characters=locale至少5个字符
181190
The_username_exists=用户名已经存在
182191
```
192+
183193
1.4.启动类
194+
184195
```
185196
import com.litongjava.hotswap.wrapper.tio.boot.TioApplicationWrapper;
186197
import com.litongjava.jfinal.aop.annotation.AComponentScan;
@@ -189,7 +200,7 @@ import com.litongjava.jfinal.aop.annotation.AComponentScan;
189200
public class MaLiangPenAiServerApp {
190201
public static void main(String[] args) {
191202
long start = System.currentTimeMillis();
192-
203+
193204
TioApplicationWrapper.run(MaLiangPenAiServerApp.class, args);
194205
//TioApplication.run(MaLiangPenAiServerApp.class, args);
195206
long end = System.currentTimeMillis();
@@ -198,7 +209,8 @@ public class MaLiangPenAiServerApp {
198209
}
199210
```
200211

201-
1.5.连接mysql
212+
1.5.连接 mysql
213+
202214
```
203215
package com.enoleap.manglang.pen.api.server.config;
204216
@@ -242,7 +254,7 @@ public class TableToJsonConfig {
242254
}
243255
244256
/*
245-
*
257+
*
246258
* config ActiveRecordPlugin
247259
*/
248260
@AInitialization
@@ -252,12 +264,12 @@ public class TableToJsonConfig {
252264
253265
ActiveRecordPlugin arp = new ActiveRecordPlugin(dataSource);
254266
arp.setContainerFactory(new OrderedFieldContainerFactory());
255-
267+
256268
Engine engine = arp.getEngine();
257269
engine.setSourceFactory(new ClassPathSourceFactory());
258270
engine.setCompressorOn(' ');
259271
engine.setCompressorOn('\n');
260-
272+
261273
if ("dev".equals(property)) {
262274
arp.setDevMode(true);
263275
engine.setDevMode(true);
@@ -270,7 +282,9 @@ public class TableToJsonConfig {
270282
}
271283
}
272284
```
273-
1.6.连接reids
285+
286+
1.6.连接 reids
287+
274288
```
275289
import com.litongjava.jfinal.aop.annotation.AConfiguration;
276290
import com.litongjava.jfinal.aop.annotation.AInitialization;
@@ -304,10 +318,12 @@ public class RedisPluginConfig {
304318
}
305319
}
306320
```
321+
307322
1.7.注册
308323
注册的业务逻辑是获取请求信息,验证请求信息,验证通过插入到数据库
309324

310325
1.7.1.UserRegisterVO
326+
311327
```
312328
import lombok.AllArgsConstructor;
313329
import lombok.Builder;
@@ -332,7 +348,9 @@ public class UserRegisterVO {
332348
333349
}
334350
```
351+
335352
1.7.2.UserRegisterController
353+
336354
```
337355
import com.litongjava.jfinal.aop.annotation.AAutowired;
338356
import com.litongjava.tio.http.server.annotation.RequestPath;
@@ -345,20 +363,22 @@ public class UserRegisterController {
345363
private UserRegisteValidator userRegisteValidator;
346364
@AAutowired
347365
private UserRegisterService userRegisterService;
348-
366+
349367
@RequestPath
350368
public RespVo index(UserRegisterVO reqVo) {
351369
RespVo respVo = userRegisteValidator.index(reqVo);
352370
if (respVo != null) {
353371
return respVo;
354372
}
355-
373+
356374
return userRegisterService.index(reqVo);
357375
}
358376
}
359377
360378
```
379+
361380
1.7.3.UserRegisteValidator
381+
362382
```
363383
package com.enoleap.manglang.pen.api.server.validator;
364384
@@ -372,7 +392,7 @@ import com.litongjava.tio.boot.i18n.Res;
372392
import com.litongjava.tio.utils.resp.RespVo;
373393
374394
public class UserRegisteValidator {
375-
395+
376396
@AAutowired
377397
private SysUserInfoService sysUserInfoService;
378398
@@ -445,7 +465,9 @@ public class UserRegisteValidator {
445465
}
446466
}
447467
```
468+
448469
1.7.4.SysUserInfoService
470+
449471
```
450472
import com.litongjava.jfinal.plugin.activerecord.Db;
451473
@@ -469,6 +491,7 @@ public class SysUserInfoService {
469491
```
470492

471493
1.7.5.UserRegisterService
494+
472495
```
473496
import com.litongjava.jfinal.plugin.activerecord.Db;
474497
import com.litongjava.tio.utils.resp.RespVo;
@@ -520,6 +543,7 @@ public class UserRegisterService {
520543

521544
1.8.单元测试注册
522545
1.8.1.TioBootTest
546+
523547
```
524548
import java.util.List;
525549
@@ -545,7 +569,9 @@ public class TioBootTest {
545569
}
546570
}
547571
```
572+
548573
1.8.2.SysUserInfoServiceTest
574+
549575
```
550576
import org.junit.Before;
551577
import org.junit.Test;
@@ -567,7 +593,9 @@ public class SysUserInfoServiceTest {
567593
568594
}
569595
```
596+
570597
1.8.3.UserRegisterServiceTest
598+
571599
```
572600
import org.junit.Before;
573601
import org.junit.Test;
@@ -596,6 +624,7 @@ public class UserRegisterServiceTest {
596624
```
597625

598626
1.8.4.UserRegisteValidatorTest
627+
599628
```
600629
import org.junit.Test;
601630
@@ -628,8 +657,9 @@ public class UserRegisteValidatorTest {
628657
}
629658
```
630659

631-
1.9.整合sa-token
660+
1.9.整合 sa-token
632661
1.9.1.SaTokenConfiguration
662+
633663
```
634664
// 导入必要的类和注解
635665
import com.litongjava.jfinal.aop.annotation.AConfiguration;
@@ -675,7 +705,9 @@ public class SaTokenConfiguration {
675705
}
676706
}
677707
```
678-
1.9.2.InterceptorConfiguration
708+
709+
1.9.2.InterceptorConfiguration
710+
679711
```
680712
// 导入必要的类和注解
681713
import com.litongjava.jfinal.aop.annotation.AConfiguration;
@@ -701,8 +733,10 @@ public class InterceptorConfiguration {
701733
}
702734
}
703735
```
736+
704737
1.10.登录
705738
1.10.1.AuthController
739+
706740
```
707741
import java.util.HashMap;
708742
import java.util.Map;
@@ -762,7 +796,9 @@ public class AuthController {
762796
}
763797
}
764798
```
799+
765800
1.10.2.AuthValidator
801+
766802
```
767803
import com.jfinal.kit.StrKit;
768804
import com.litongjava.tio.boot.i18n.I18n;
@@ -779,11 +815,11 @@ public class AuthValidator {
779815
} else {
780816
res = I18n.use(I18nLocale.EN_US);
781817
}
782-
818+
783819
if (StrKit.isBlank(locale)) {
784820
return RespVo.fail(res.get("The_locale_cannot_be_empty"));
785821
}
786-
822+
787823
if(StrKit.isBlank(username) || StrKit.isBlank(password)) {
788824
String string = res.get("The_username_or_password_cannot_be_empty");
789825
return RespVo.fail(string);
@@ -792,7 +828,9 @@ public class AuthValidator {
792828
}
793829
}
794830
```
831+
795832
1.10.3.AuthService
833+
796834
```
797835
import com.litongjava.jfinal.plugin.activerecord.Db;
798836
import com.litongjava.tio.utils.resp.RespVo;
@@ -817,6 +855,7 @@ public class AuthService {
817855

818856
1.11.发送请求测试
819857
1.11.1.注册
858+
820859
```
821860
curl --location --request POST 'http://localhost:9204/pen-api/user/register' \
822861
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
@@ -834,6 +873,7 @@ curl --location --request POST 'http://localhost:9204/pen-api/user/register' \
834873
```
835874

836875
1.11.2.登录
876+
837877
```
838878
curl --location --request POST 'http://localhost:9204/pen-api/auth/doLogin' \
839879
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
@@ -846,14 +886,17 @@ curl --location --request POST 'http://localhost:9204/pen-api/auth/doLogin' \
846886
--data-urlencode 'locale=zh_CN'
847887
```
848888

849-
响应头中保护token
889+
响应头中保护 token
850890
响应体如下
891+
851892
```
852893
{
853894
"ok": true
854895
}
855896
```
856-
1.11.3.验证token是否有效
897+
898+
1.11.3.验证 token 是否有效
899+
857900
```
858901
curl --location --request GET 'http://localhost:9204/pen-api/auth/validateToken' \
859902
--header 'token: 4eb6ac726a7d4f42bb10fe365823f9f7' \
@@ -863,14 +906,15 @@ curl --location --request GET 'http://localhost:9204/pen-api/auth/validateToken'
863906
--header 'Connection: keep-alive' \
864907
```
865908

866-
1.11.4.获取用户id
909+
1.11.4.获取用户 id
910+
867911
```
868912
curl --location --request GET 'http://localhost:9204/pen-api/auth/getUserId' \
869913
--header 'token: 4eb6ac726a7d4f42bb10fe365823f9f7' \
870914
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
871915
--header 'Accept: */*' \
872916
--header 'Host: localhost:9204' \
873-
--header 'Connection: keep-alive'
917+
--header 'Connection: keep-alive'
874918
```
875919

876920
```
@@ -883,7 +927,9 @@ curl --location --request GET 'http://localhost:9204/pen-api/auth/getUserId' \
883927
    "ok": true
884928
}
885929
```
930+
886931
1.11.5.登出
932+
887933
```
888934
curl --location --request GET 'http://localhost:9204/pen-api/auth/logout' \
889935
--header 'token: 4eb6ac726a7d4f42bb10fe365823f9f7' \
@@ -892,4 +938,3 @@ curl --location --request GET 'http://localhost:9204/pen-api/auth/logout' \
892938
--header 'Host: localhost:9204' \
893939
--header 'Connection: keep-alive'
894940
```
895-

docs/zh/99_案例/02.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tio-boot 案例 异常捕获与企业微信群通知案例
1+
# tio-boot 案例 异常捕获与企业微信群通知
22

33
## 概述
44

0 commit comments

Comments
 (0)