-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
邝华
committed
Sep 15, 2021
1 parent
fe4d8dd
commit d19e01c
Showing
43 changed files
with
3,976 additions
and
1,219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,108 @@ | ||
### 简介: | ||
|
||
#### 更新日志 | ||
``` | ||
vue3-admin-template 的数据来源 | ||
涉及到的功能:jwt 权限校验,token过期,续约(有效期为3天,少于一天自动更新token),文件导入和上传, | ||
用户相关操作等,多环境切换(dev,prod)等 | ||
// 2021-09-15 | ||
1.增加了文件上传下载,为vue3-element-plus提供例子数据 | ||
``` | ||
|
||
##### 使用的技术: | ||
|
||
### 前言 | ||
``` | ||
本架构使用的技术为: | ||
spring-boot:2.1.4.RELEASE | ||
spring-cloud:Greenwich.SR1 | ||
spring-cloud-starter-gateway:2.1.1.RELEASE | ||
nacos:2.1.3.RELEASE | ||
mybatis-plus: 3.3.2 | ||
rabbitmq 等 | ||
rabbitmq:3.7-management | ||
redis: 3.2.9 | ||
mysql:5.7 | ||
``` | ||
|
||
#### swager文档地址: | ||
|
||
http://8.135.1.141/micro-service-doc/swagger-ui.html | ||
|
||
#### nacos地址(naocs配置请不要删除): | ||
|
||
http://8.135.1.141:8848/nacos/ | ||
|
||
用户名:jzfai | ||
密码:123456 | ||
|
||
#### 微服务(后续还会新增新的微服务) | ||
|
||
``` | ||
ty-common: 统一依赖,统一配置管理,feign接口整合等 | ||
本架构的微服务有: | ||
ty-gateway:网关微服务。使用的是spring-cloud-starter-gateway,先对于zull网关来说性能更好。主要实现了,权限控制和拦截,jwt token解析和校验,swagger文件整合,使用令牌技术请求限流等 | ||
ty-auth:权限服务。jwt token生成,解析,校验等,默认配置3天有效期,少于一天自动续约(此处感兴趣的可以查看下源码) | ||
ty-user:用户服务。用户的登录,注册,查看用户信息等一系列功能 | ||
ty-upload:文件上传服务。使用的技术为fastDFS技术,此服务主要用于文件的上传和下载 | ||
``` | ||
|
||
#### 亮点: | ||
|
||
``` | ||
1.在网关中将jwt token和解析后的token信息已经设置在请求头中,在后续转发的微服务可以在请求头中轻松的拿到token和token解析后的数据,不用再通过feign去调用ty-auth获取token信息 | ||
``` | ||
|
||
![1631692199271](http://8.135.1.141/file/images/1631692199271.png) | ||
|
||
``` | ||
2.此时微服务已经可以在请求通中获取到token和信息,但是feign调用其他微服务的时候却出现了token丢失的情况,此时需要在feign调用服务时将请求头一起转发,那么微服务之前调用时也能获取都token和信息 | ||
``` | ||
|
||
![1631692308212](http://8.135.1.141/file/images/1631692308212.png) | ||
|
||
``` | ||
3.少于1天时间自动更新token,主要通过gateway的两个拦截器来完成 | ||
AuthorizeFilterBefore:请求前拦截。解析token的有效性和是否过期,和配置了白名单的请求方法进行放行 | ||
AuthorizeFilterAfter:请求后拦截。主要用于token更新校验,和生产新的token,通过isNeedUpdateToken字段告诉前端要更新token | ||
如果想知道前端如何更新token可查看: | ||
https://github.com/jzfai/vue3-admin-template | ||
``` | ||
|
||
![1631693000767](http://8.135.1.141/file/images/1631693000767.png) | ||
|
||
``` | ||
4.多环境和nacos: | ||
开发人员可以快速的切换环境以达到开发的目的 | ||
目前为止只添加了 | ||
dev:开发时使用的分支 | ||
prod:发布是切换的分支 | ||
注:配置环境时请在nacos上添加相应的配置文件,不然会报错 | ||
nacos: | ||
注册中心: | ||
通过discovery进行配置,具体可查看源码 | ||
配置中心: | ||
加载顺序:naocs默认加载的config配置文件-> shared-configs->extension-configs | ||
优先级:naocs默认加载的config配置文件->extension-configs-> shared-configs | ||
``` | ||
|
||
![1631693866876](http://8.135.1.141/file/images/1631693866876.png) | ||
|
||
![1631694125676](http://8.135.1.141/file/images/1631694125676.png) | ||
|
||
``` | ||
#### swagger文档 http://8.135.1.141:30156/swagger-ui.html | ||
#### 感兴趣可以看下 | ||
5.easycode模板配置: | ||
本架构提供了基本的版本生成,可以快速生成,实现前后端的增删改查,前端的easycode生成的模板适配vue-element-template架构,可以把模板直接复制到easycode中生成相应的代码 | ||
不会使用easycode可以查看这里 | ||
https://www.jianshu.com/p/e4192d7c6844 | ||
``` | ||
|
||
![1631695768271](http://8.135.1.141/file/images/1631695768271.png) | ||
|
||
### 如何运行 | ||
|
||
```javascript | ||
克隆项目 | ||
git clone https://github.com/jzfai/micro-service-plus.git | ||
用idea打开项目,加载下载依赖即可运行 | ||
``` | ||
|
||
>注:本项目加入了热更新:运行项目后,使用ctrl+F9快捷键或rebuild下就行直接更新服务 | ||
#### 如果需要实时交流的可以加入wx群(有vue3+ts视频教程) | ||
|
||
![http://8.135.1.141/file/images/wx-groud.png](http://8.135.1.141/file/images/wx-groud.png) | ||
|
||
大家的支持是我前进的动力 欢迎加入一起开发 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
##导入宏定义 | ||
$!init | ||
$!define | ||
|
||
##设置表后缀(宏定义) | ||
#setTableSuffix("Controller") | ||
|
||
##保存文件(宏定义) | ||
#save("/controller", "Controller.java") | ||
|
||
##包路径(宏定义) | ||
#setPackageSuffix("controller") | ||
|
||
##定义服务名 | ||
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) | ||
|
||
##定义实体对象名 | ||
#set($entityName = $!tool.firstLowerCase($!tableInfo.name)) | ||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
import com.baomidou.mybatisplus.extension.api.ApiController; | ||
import com.baomidou.mybatisplus.extension.api.R; | ||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
##import $!{tableInfo.savePackageName}api.entity.$!tableInfo.name; | ||
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.annotation.Resource; | ||
import java.io.Serializable; | ||
import java.util.*; | ||
|
||
##表注释(宏定义) | ||
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") | ||
@RestController | ||
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)") | ||
public class $!{tableInfo.name}Controller { | ||
|
||
@Resource | ||
private $!{tableInfo.name}Service $!{serviceName}; | ||
|
||
/** | ||
* 分页查询所有数据 | ||
* @param $!entityName 查询实体 | ||
* @return 所有数据 | ||
*/ | ||
@GetMapping("selectPage") | ||
@ApiOperation(value = "分页查询所有数据") | ||
public ResResult selectPage($!{tableInfo.name} $!entityName, KHCommonParams khCommonParams) { | ||
QueryWrapper<$!{tableInfo.name}> queryWrapper = new QueryWrapper<>(); | ||
#foreach($column in $tableInfo.fullColumn) | ||
#if( $!column.comment ) | ||
if(ObjectUtils.isNotEmpty($!{entityName}.get$!{tool.firstUpperCase($column.name)}())) { | ||
queryWrapper.or().like("$!{column.name}",$!{entityName}.get$!{tool.firstUpperCase($column.name)}()); | ||
} | ||
#end | ||
#end | ||
|
||
#set($StringBj="") | ||
#foreach($column in $tableInfo.fullColumn) | ||
#if( $!column.comment ) | ||
#set($StringBj=$!{StringBj}+$!{tool.hump2Underline($column.name)}+",") | ||
#end | ||
#end | ||
|
||
|
||
queryWrapper.or().orderByDesc("create_time"); | ||
if(StringUtils.isNotEmpty(commonParams.getStartTime())) { | ||
queryWrapper.or().between("create_time",commonParams.getStartTime(),commonParams.getEndTime()); | ||
} | ||
queryWrapper.select("$StringBj.substring(0,$StringBj.lastIndexOf(','))"); | ||
Page<$!{tableInfo.name}> $!{entityName}Page = this.$!{entityName}Service.selectPage(khCommonParams.getPageNum(), khCommonParams.getPageSize(), queryWrapper); | ||
return new ResResult().success($!{entityName}Page); | ||
} | ||
|
||
/** | ||
* 通过主键查询单条数据 | ||
* @param id 主键 | ||
* @return 单条数据 | ||
*/ | ||
@GetMapping("selectById") | ||
@ApiOperation(value = "通过id主键查询单条数据") | ||
public ResResult selectById(@RequestParam("id") Integer id) { | ||
return new ResResult().success(this.$!{serviceName}.selectById(id)); | ||
} | ||
|
||
/** | ||
* @Description: 根据id数组查询品牌列表 | ||
* @Param: idList id数组 | ||
* @return: ids列表数据 | ||
*/ | ||
@ApiOperation(value = "根据id数组查询品牌列表") | ||
@PostMapping("selectBatchIds") | ||
public ResResult selectBatchIds(@RequestParam("idList") List | ||
<Integer> idList) { | ||
return new ResResult().success(this.$!{serviceName}.selectBatchIds(idList)); | ||
} | ||
/** | ||
* 新增数据 | ||
* @param $!entityName 实体对象 | ||
* @return 新增结果 | ||
*/ | ||
@ApiOperation(value = "新增数据") | ||
@PostMapping("insert") | ||
public ResResult insert(@RequestBody $!{tableInfo.name} $!entityName) { | ||
return new ResResult().success(this.$!{serviceName}.insert($!entityName)); | ||
} | ||
|
||
/** | ||
* 修改数据 | ||
* @param $!entityName 实体对象 | ||
* @return 修改结果 | ||
*/ | ||
@ApiOperation(value = "根据id修改数据") | ||
@PutMapping("updateById") | ||
public ResResult updateById(@RequestBody $!{tableInfo.name} $!entityName) { | ||
return new ResResult().success(this.$!{serviceName}.updateById($!entityName)); | ||
} | ||
|
||
/** | ||
* 删除数据 | ||
* @param idList 主键结合 | ||
* @return 删除结果 | ||
*/ | ||
@ApiOperation(value = "根据id数组删除数据") | ||
@DeleteMapping("deleteBatchIds") | ||
public ResResult deleteBatchIds(@RequestBody List | ||
<Long> idList) { | ||
return new ResResult().success(this.$!{serviceName}.deleteBatchIds(idList)); | ||
} | ||
|
||
@DeleteMapping("deleteById") | ||
@ApiOperation(value = "根据id数组删除数据") | ||
public ResResult deleteById(@RequestParam("id") Integer id) { | ||
return new ResResult().success(this.$!{serviceName}.deleteById(id)); | ||
} | ||
} |
Oops, something went wrong.