我是小白记录一下学习的东西 大佬看见勿喷

1.2我常用封装状态

@Data
@AllArgsConstructor
public class BaseApiController<T> {

    private Integer code ;

    private String  msg;

    private T data;

    public  static <T>  BaseApiController<T> Response_success(String msg,Integer code,T data){

         return   new BaseApiController<>(code,msg,data);
    }

    public  static <T>  BaseApiController<T> Response_error(String msg,Integer code){

        return   new BaseApiController<>(code,msg,null  );
    }



}

2. 我目前用的yml配置

#当前端口号
server:
  port: 9090

mybatis-plus:
  configuration:
    # mybatisPlus 日志
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    #  myabtisPlus mapper配置文件夹目录
    mapper-locations: classpath:/mapper/*.xml
spring:
  servlet:
    multipart:
    # 设置最大请求文件大小
      max-request-size: 50MB
    #设置单个文件大小
      max-file-size: 10MB
  #druid数据源链接配置
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    url:  jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
    username: root
    password: abc123

3.MD5封装加密密码

public static String md5(String source) {

    // 1.判断 source 是否有效
    if (source == null || source.length() == 0) {
        // 2.如果不是有效的字符串抛出异常
        throw new RuntimeException("字符串不可为空");
    }
    try {
        // 3.获取 MessageDigest 对象
        String algorithm = "md5";
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        // 4.获取明文字符串对应的字节数组
        byte[] input = source.getBytes();
        //执行加密
        byte[] output = messageDigest.digest(input);
        // 6.创建 BigInteger 对象
        int signum = 1;
        BigInteger bigInteger = new BigInteger(signum, output);
        // 7.按照 16 进制将 bigInteger 的值转换为大写字符串
        int radix = 16;
        String encoded = bigInteger.toString(radix).toUpperCase();
        return encoded;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        log.error("e:{}", e);
        return null;
    }
}

public static void main(String[] args) {
    String pwd = MD5Utils.md5("123456");
    System.out.println(pwd);
}

4.拿到随机盐值

public static String getSalt() {
    return UUID.randomUUID().toString().replace("-", "");
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值