当前位置:网站首页>工具类总结
工具类总结
2022-08-05 00:43:00 【周雨彤的小迷弟】
MD5加密工具类:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public final class MD5 {
public static String encrypt(String strSrc) {
try {
char hexChars[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f' };
byte[] bytes = strSrc.getBytes();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
bytes = md.digest();
int j = bytes.length;
char[] chars = new char[j * 2];
int k = 0;
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
chars[k++] = hexChars[b >>> 4 & 0xf];
chars[k++] = hexChars[b & 0xf];
}
return new String(chars);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException("MD5加密出错!!+" + e);
}
}
public static void main(String[] args) {
System.out.println(MD5.encrypt("111111"));
}
}
ResponseUtil :
写出 response 流
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class ResponseUtil {
public static void out(HttpServletResponse response, R r) {
ObjectMapper mapper = new ObjectMapper();
response.setStatus(HttpStatus.OK.value());
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
try {
mapper.writeValue(response.getWriter(), r);
} catch (IOException e) {
e.printStackTrace();
}
}
}
边栏推荐
- SV 类的虚方法 多态
- PCIe 核配置
- 2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
- torch.autograd.grad求二阶导数
- leetcode: 269. The Martian Dictionary
- Software testing interview questions: How many types of software are there?
- gorm的Raw与scan
- Software testing interview questions: test life cycle, the test process is divided into several stages, and the meaning of each stage and the method used?
- QSunSync Qiniu cloud file synchronization tool, batch upload
- Lattice PCIe 学习 1
猜你喜欢
随机推荐
NMS原理及其代码实现
Lattice PCIe 学习 1
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
软件基础的理论
典型相关分析CCA计算过程
SV class virtual method of polymorphism
2022牛客多校第三场 A Ancestor
Matlab uses plotting method for data simulation and simulation
Software testing interview questions: What are the strategies for system testing?
Software test interview questions: BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
oracle创建表空间
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
gorm联表查询-实战
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
2022 Hangzhou Electric Power Multi-School Session 3 Question L Two Permutations
The method of freely controlling concurrency in the sync package in GO
torch.autograd.grad求二阶导数
进程间通信和线程间通信
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
Software testing interview questions: Have you used some tools for software defect (Bug) management in your past software testing work? If so, please describe the process of software defect (Bug) trac









