# dev_platform_springBoot **Repository Path**: lcc5050/dev_platform_springBoot ## Basic Information - **Project Name**: dev_platform_springBoot - **Description**: 学习spring boot cloud 开发 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-09-29 - **Last Updated**: 2024-08-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### nacos 配置 Data Id:应用名称-分组.yaml #### 数据库配置 mysql-dev.yaml ```yaml spring: datasource: name: dev_platform driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/dev_platform?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true username: dev_platform password: dev_platform type: com.zaxxer.hikari.HikariDataSource hikari: connection-timeout: 30000 minimum-idle: 5 maximum-pool-size: 20 auto-commit: true idle-timeout: 600000 pool-name: DataSourceHikariCP max-lifetime: 1800000 connection-test-query: select 1 ``` #### 系统公共配置 public-dev.yaml ```yaml server: servlet: encoding: charset: utf-8 spring: jackson: time-zone: Asia/Shanghai thymeleaf: enabled: true encoding: utf-8 prefix: classpath:/templates/ cache: false mode: HTML suffix: .html mvc: view: suffix: action pathmatch: matching-strategy: ANT_PATH_MATCHER mybatis-plus: configuration: map-underscore-to-camel-case: false auto-mapping-behavior: full log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: classpath*:mapper/**/*Mapper.xml global-config: db-config: logic-delete-value: 1 logic-not-delete-value: 0 logging: level: com.lzy: debug ``` #### 缓存管理 redis-dev.yaml ```yaml spring: redis: host: 127.0.0.1 port: 8078 password: 123456 timeout: 10s lettuce: pool: min-idle: 0 max-idle: 8 max-active: 8 max-wait: -1ms # 集群配置 cluster: max-redirects: 3 # 最大重定向次数 # 集群节点 nodes: - 10.16.1.238:8996 - 10.16.1.239:8991 ``` #### 缓存管理 redisson-dev.yaml ```yaml spring: redis: # redisson配置 redisson: # 如果该值为false,系统将不会创建RedissionClient的bean。 enabled: true # mode的可用值为,single/cluster/sentinel/master-slave mode: single # single: 单机模式 # address: redis://localhost:6379 # cluster: 集群模式 # 每个节点逗号分隔,同时每个节点前必须以redis://开头。 # address: redis://localhost:6379,redis://localhost:6378,... # sentinel: # 每个节点逗号分隔,同时每个节点前必须以redis://开头。 # address: redis://localhost:6379,redis://localhost:6378,... # master-slave: # 每个节点逗号分隔,第一个为主节点,其余为从节点。同时每个节点前必须以redis://开头。 # address: redis://localhost:6379,redis://localhost:6378,... address: redis://127.0.0.1:8078 # redis 密码,空可以不填。 password: 123456 database: 0 ``` #### token加密密钥 rsa-dev.yaml ```yaml rsa: key: pubKeyPath: /home/lcc/DevProjects/dev_platform_springBoot/rsa/id_key_rsa.pub priKeyPath: /home/lcc/DevProjects/dev_platform_springBoot/rsa/id_key_rsa ``` #### 平台参数配置 platform-dev.yaml ```yaml platform: db: mysql user: def-pwd: 123456 upload-file: path: /data/home/lcc/temp/fileRes ftp: true ftp-ip: 8.141.160.123 ftp-port: 22 ftp-user: sftp_test ftp-pwd: sftp@2023 ftp-type: sftp ftp-path: /home/sftp_test/uploadFile ``` ### 生产公钥和私钥 ```java private String privateFilePath = "d:\\id_key_rsa"; private String publicFilePath = "d:\\id_key_rsa.pub"; @Test public void generateKey() throws Exception { RsaUtils.generateKey(publicFilePath,privateFilePath,"lzy",2048); } ``` ### 启动顺序 ``` 1.nacos (配置中心) 2.com.lzy.gateway(网关) 3.com.lzy.authorizationServer(用户认证中心 Jwt token) 4.其他服务 ``` ### 关于端口(优先使用启动参数配置的端口) ``` 如果不通过命令启动行进行设置,系统会随机端口启动50000-60000之间随机端口 ``` ### 语言切换 ``` 支持两种语言 zh-CN,en-US 在请求头中添加:如果请求头没有语言设置默认是获取操作系统语音 accept-language:zh-CN ``` ### libreoffice 启动器 先安装libreoffice ,开启启动器后可以自动启动libreoffice转换服务 1.maven引入坐标 ```xml com.lzy com.lzy.libreoffice.autoconfiguration 1.0-SNAPSHOT ``` 2.yaml 开始配置 ```yaml libreoffice: path: D:/Program Files/LibreOffice # LibreOffice 安装地址 port: 2002 # 多个端口示例 2002,2001 enabled: true ``` 3.使用转换 ```text @Autowired private LibreofficeService libreofficeService; libreofficeService.office2Pdf("源文件(pdf)","目标文件(pdf)"); ``` ### spring security ``` 登录地址:http://127.0.0.1/service-login/login 登录成功后在响应头里面获取:Authorization(token) 对应需要认证的地址需要在请求头中添加 Authorization=登录获取的token ``` ### springfox ``` http://127.0.0.1/模块名称/swagger-ui/index.html 示例地址:http://127.0.0.1/service-adminManage/swagger-ui/index.html ``` --- ### adminManage 模块记录 ```yaml 登陆地址 http://127.0.0.1:1025/service-adminManage-ui/login.html 用户名 admin/123 lcc/123 ``` ### 缓存注解 @RedisCache 可以自动把返回值缓存到redis中 ##### 注解参数 ###### value: 表示方法的参数 {"user","dep"} ###### key: 表示redis中的前缀 ###### extKey: 可以用户自定义的后缀(支持spel) key:extKey ```text //用户查询自己的权限缓存到redis中 @RedisCache(value = {"uid"}, key = "user:res_list", extKey = "#uid"); public List queryByUid(String uid){ List sysRes=sysResRoleMapper.queryByUid(uid); return sysRes; } ``` ### 缓存删除注解 @RedisCacheDel 可以删除redis中的key ##### 注解参数 ###### value: 表示方法的参数 {"user","dep"} ###### key: 表示redis中的前缀(支持通配符) ###### extKey: 可以用户自定义的后缀(支持spel) key:extKey ###### isFor: 是否循环 extKey 解析后的字符串 默认false ##### separate: 切割 extKey 解析后的字符串的切割符号 默认 ,(逗号) ###### ```text //资源重新授权后清空所有的用户权限缓存 @RedisCacheDel(key = "user:res_list*") public void savePowerByResId(Long resId, List sysRoles) throws BusException{ } //切割使用例子 //用户缓存是 user:entity:id //由于保存用户是可以批量保存的。所有需要把list里面的id拼接成 逗号间隔的id 如:1,2,3 。然后配置isFor=true, aop中会按照配置的 separate 切割成一个数组。循环 user:entity:arr[i] 找缓存key然后删除 @RedisCacheDel(value = {"users"}, key = "user:entity",isFor = true, extKey = "T(org.springframework.util.StringUtils).collectionToDelimitedString(#users.![id], ',')") public boolean update(List sysUserDTOs) throws BusException { List sysUsers = new ArrayList<>(); for (SysUserDTO sysUserDTO : sysUserDTOs) { SysUser sysUser = (SysUser) BeanMapHelper.Bean2Bean(sysUserDTO, SysUser.class); sysUsers.add(sysUser); } boolean update = this.updateBatchById(sysUsers); if (!update) { throw new BusException(i18nService.getMessage("system.org.user.update.fail")); } return update; } ``` ### contorller注入用户对象 通过 HandlerMethodArgumentResolver 和 WebMvcConfigurer:addArgumentResolvers 实现 ```java @RequestMapping(value = "/saveFile", method = RequestMethod.POST) @ApiOperation("上传文件") public JSONResult uploadFile(SysUser user, @ApiParam("文件") @RequestParam("file") MultipartFile file) { if (file.isEmpty()) { return JSONResult.errorMsg("必须上传文件"); } return JSONResult.ok(iSysFileService.saveFile(user.getId(), file)); } ``` ### 通用建表语句 实体类继承 CommonEntity ```sql create table tableName ( id varchar(32) comment '唯一标识', # 中间可以任意怎加字段进行表结构的创建 create_time timestamp not null default CURRENT_TIMESTAMP comment '数据插入数据库的时间', update_time timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改数据库数据的时间', version int(11) not null comment '最新版本号', del_flag tinyint not null comment '删除标记(0-否,1-是)', primary key (id) using BTREE )engine = InnoDB DEFAULT CHARSET=utf8mb4 comment "表描述"; ``` ### ai 自动生成业务表 ``` 你作为一个名oa系统软件产品设计经理,我要在mysql数据库新建一些业务表,请给我推荐一些相关字段,使用Markdown格式输出json,并且格式化json。 json要求如下: fieldtitle:标题 fieldname:字段名称 fieldtype:字典类型(和mysql中类型一致) fieldlength:字段长度 json示例: [{fieldtitle:'test',fieldname:'test',fieldtype:'varchar',fieldlength:'50'}] 我会输入具体的业务模块名字,你准备好了。请回复 好的 ``` ### excel操作(easyexcel) 官网教程: https://easyexcel.opensource.alibaba.com/docs/current/ ### es操作(easy-es) 官网教程:https://www.easy-es.cn/ ### 工具类(hutool) 官网教程:https://hutool.cn/ ### 云存储(x-file-storage) 官网教程:https://x-file-storage.xuyanwu.cn ```java 在启动类上加上注解 @EnableFileStorage 配置文件看官网 ``` #redisson (redis工具) 官网教程: ### 更新日志 2024-01-17 1. token续签(如果token到期10分钟前还在使用就续签) 2024-01-09 1. 实现代码生成器 2024-01-05 1. 修改jdk17版本 2. 完成字典管理 3. 修复mvn package 报错问题 4. 更新nacos 配置备份 5. 更新数据库备份文件 2024-01-04 1. jwt直接解密获得一个简易的用户对象 2. jwt过滤器中给security上下文添加用户对象 3. redis缓存注解新增字段(详情看上面使用) 4. 字典维护(未完成) 2023-12-31 1. 新增附件上传 2. 新增附件下载 3. 修改密码 4. 修改个人信息 5. conntorller注入用户对象 6. 修改nacos配置 2023-12-20 1. 新增缓存注解(详情看上面的介绍) 2. 角色管理,资源管理,导航管理,权限分配,修改密码