Loading

龙行博客

“后端“

后端相关

使用Token机制,保证请求幂等

幂等有很多方案,但是个人觉得这个最好用,来一个示例方案先 我们使用Redis保存Token令牌,引入SpringBoot,Redis,ULID相关的依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.7.0</version> </depend...

收藏一个Hyperf好用的ENUM

地址: https://github.com/lishuncoder/enums 没用过,但是收藏一波 提供两种枚举的应用,一种是对常规枚举类的加强和扩展,即枚举类扩展,继承原枚举类原生功能的基础上拓展了注解属性,出发点源自于一些枚举的值确实一致但意义却不一样的场景: tb_user.gender: 0 未知 1 男 2 女 tb_user.type: 0 普通 1 特殊类型1 2 特殊类型2 此时值确实一致,但需要的解释和描述却完全不一致,这是通过 const 常量的注解已经无法实现这个功能,或者只能将原 const 值 变为数组,这并不优雅,这时...

springboot3.0.7-redis配置记录下

配置redis一直报错,想都不用想肯定是版本原因,各种折腾终于解决 正确的配置能用版本, 记录下 <?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://mav...

SpringBoot注解验证的操作方法

一样的做个记录,每次找资料耗费时间 场景: 嗯! 就是. 对接收参数进行合规性校验 目前我知道的有两种方式 第一种 直接写在Controller的方法中 public HttpResult test(@NotNull(message = "缺少参数:id") Long id) 第二种: 写在实体类中 /** * @desc: 运单新增请求bean * @author: Lt * @date: 2024/3/25 17:17 */ @Setter @Getter @Accessors(chain = true) public...

SpringBoot捕获自定义message

做个记录吧,虽然到处都是 package com.driver.businessmodules.handler; import com.utils.businesscommonutils.HttpResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.web.bind.MethodArgumentNotValidException; imp...

SpringBoot+Netty TCP协议对接充电桩

只是记录下使用记录,fd和uid的绑定没有写 引入依赖 <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.22.Final</version> </dependency> 创建编码器,解码器 编码器 // 编码器 package com.example.springbootnettyserver...

maven阿里镜像配置

每次都要去找比较麻烦,挪过来自己看的😁 ▪apache mavne中央仓库 ▪https://search.maven.org/ ▪https://mvnrepository.com/ 方式一:全局配置 可以添加阿里云的镜像到maven的setting.xml配置中,这样就不需要每次在pom中,添加镜像仓库的配置,在mirrors节点下面添加子节点: <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> &...

SpringBoot日期格式化多种方式

@JsonFormat 注解方式 在单个实体类属性上添加个注解 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startDate; 前端参数传递 { "startDate" : "2024-02-26 15:15:15" } 这个方式比较自由,缺点就是麻烦,每个实体类都得写 全局格式化方式 全局配置,后续可以不用单独加注解 package com.xy.config; import com.fasterxml.jackson.databind....

Git远程分支的删除与刷新

刷新远程分支 git remote update origin --prune 远程分支拉取到本地并切换git pull git checkout -b 本地分支名 origin/远程分支名 删除本地分支 -d 不能包含未合并的更改和未推送的提交 -D 带有大写-- delete --force字母D(它是 的别名)的标志会强行删除本地分支 git branch -D local_branch_name git branch -d local_branch_name 删除远程分支 git push origin --delete dist-notice ...

MySQL自动备份脚本

mysqldump命令将数据库中的数据备份成一个文本文件,表的结构和数据将存储在生成的文本文件中 备份数据库多个表 # 备份一个数据库下的多个表 # username表示用户名 # pwd表示密码 # localhost为数据库地址 # dbname表示数据库名称 # table1和table2参数表示需要备份的表的名称,为空则整个数据库备份 mysqldump -u username -p pwd -h localhost --default-character-set=utf8 dbname table1 table2 > BackupNam...