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("-", ""); }