设为首页
收藏本站
首页
自丢网
产品
软件开发产品
教程
联系
联系我们
热搜
活动
交友
discuz
登录
自丢网
»
教程
›
【教程】编程记录
›
JAVA教程
›
java中jar工具包hutool的作用
返回列表
发新帖
java中jar工具包hutool的作用
[复制链接]
admin
发表于 2025-8-21 11:05:04
|
显示全部楼层
|
阅读模式
java中jar工具包hutool的作用
Hutool 简介
Hutool 是一个功能丰富且易用的Java工具库,涵盖了字符串处理、日期时间操作、文件操作、加密解密、HTTP请求、JSON处理等各个方面。它的设计目标是尽量减少开发人员在项目中编写重复代码的工作量。
主要功能模块
hutool-core - 核心模块,包含字符串、日期、集合等基础工具
hutool-json - JSON处理工具
hutool-http - HTTP客户端工具
hutool-crypto - 加密解密工具
hutool-setting - 配置文件工具
hutool-cache - 缓存工具
hutool-db - 数据库工具
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.27</version>
</dependency>
复制代码
案例:
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.itheima.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
public class UserController {
@RequestMapping("/list")
public String list(){
//1.加载并读取文件
InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt");
ArrayList<String> lines = IoUtil.readLines(in, StandardCharsets.UTF_8, new ArrayList<>());
//2.解析数据,封装成对象 --> 集合
List<User> userList = lines.stream().map(line -> {
String[] parts = line.split(",");
Integer id = Integer.parseInt(parts[0]);
String username = parts[1];
String password = parts[2];
String name = parts[3];
Integer age = Integer.parseInt(parts[4]);
LocalDateTime updateTime = LocalDateTime.parse(parts[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
return new User(id, username, password, name, age, updateTime);
}).collect(Collectors.toList());
//3.响应数据
//return JSONUtil.toJsonStr(userList, JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss"));
return userList;
}
}
复制代码
java教程
,
springboot教程
相关帖子
•
java获取请求参数案例代码和设置响应数据
•
JAVA创建一个SpringBoot工程项目
•
java中spring附件上传本地储存方法
•
cookie会话Session会话和JWT令牌优缺点对比
•
过滤器Filter、拦截器Interceptor,过滤器和拦截器的区别
•
SpringBoot配置文件的优先级
网站建设,公众号小程序开发,多商户单商户小程序制作,高端系统定制开发,App软件开发联系我们【手机/微信:
17817817816
】
回复
举报
返回列表
发新帖
微信扫码
Archiver
|
手机版
|
自丢网
网站建设,公众号小程序开发,商城小程序,系统定制开发,App软件开发等
粤ICP备2024252464号
在本版发帖
微信扫码
QQ客服
返回顶部
快速回复
返回顶部
返回列表