当前位置:网站首页>工具类总结
工具类总结
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();
}
}
}
边栏推荐
- [FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
- Software Testing Interview Questions: What aspects should be considered when designing test cases, i.e. what aspects should different test cases test against?
- 软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
- QSunSync Qiniu cloud file synchronization tool, batch upload
- Helm Chart
- 活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
- 2022 Nioke Multi-School Training Session H Question H Take the Elevator
- 关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
- MBps与Mbps区别
- 2022杭电多校第三场 L题 Two Permutations
猜你喜欢
Inter-process communication and inter-thread communication
4. PCIe 接口时序
创意代码表白
"WEB Security Penetration Testing" (28) Burp Collaborator-dnslog out-band technology
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
PCIe 核配置
JUC thread pool (1): FutureTask use
leetcode:266. 回文全排列
matlab中rcosdesign函数升余弦滚降成型滤波器
Lattice PCIe 学习 1
随机推荐
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?
Opencv——视频跳帧处理
金九银十面试跳槽季;你准备好了吗?
E - Many Operations (按位考虑 + dp思想记录操作后的结果
JUC线程池(一): FutureTask使用
Will domestic websites use Hong Kong servers be blocked?
MongoDB construction and basic operations
Software testing interview questions: How many types of software are there?
2022杭电多校第三场 L题 Two Permutations
2022 Hangzhou Electric Power Multi-School Session 3 Question L Two Permutations
More than 2022 cattle school training topic Link with the second L Level Editor I
仅3w报价B站up主竟带来1200w播放!品牌高性价比B站投放标杆!
leetcode:269. 火星词典
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
Mysql_13 事务
Pytorch使用和技巧
刘润直播预告 | 顶级高手,如何创造财富
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
JUC thread pool (1): FutureTask use
leetcode:267. 回文排列 II