当前位置:网站首页>Hutool - 轻量级 DB 操作解决方案
Hutool - 轻量级 DB 操作解决方案
2022-07-07 15:47:00 【放羊的牧码】
故事背景
有时候,我们并不一定需要用到 Hibernate、JPA、Mybatis 等比较重量级的框架去操作数据库,原生自带的 JDBC 那一套也感觉太繁琐,今天给大家带来一套 Hutool 版的数据库操作方案
Maven
<!--mysql数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
方式一
DataSource ds = new SimpleDataSource("jdbc:mysql://localhost:3306/lux?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai", "root", "123456");
Db db = DbUtil.use(ds);
List<TagPO> rs = db.query("select * from t_as_tag", TagPO.class);
方式二
## db.setting文件
url = jdbc:mysql://localhost:3306/test
user = root
pass = 123456
## 可选配置
# 是否在日志中显示执行的SQL
showSql = true
# 是否格式化显示的SQL
formatSql = false
# 是否显示SQL参数
showParams = true
# 打印SQL的日志等级,默认debug,可以是info、warn、error
sqlLevel = debug
List<Entity> result = Db.use().query("select * from user where age < ?", 3);
参考文档
边栏推荐
- yolo训练过程中批量导入requirments.txt中所需要的包
- 三仙归洞js小游戏源码
- cf:C. Factorials and Powers of Two【dp + 排序 + 选不选板子 + 选若干个数等于已知和的最少数】
- 简单的loading动画
- 【OKR目标管理】价值分析
- Deep learning machine learning various data sets summary address
- 基于百度飞浆平台(EasyDL)设计的人脸识别考勤系统
- 开发一个小程序商城需要多少钱?
- Actionbar navigation bar learning
- Easy to understand [linear regression of machine learning]
猜你喜欢
Please insert the disk into "U disk (H)" & unable to access the disk structure is damaged and cannot be read
< code random recording two brushes> linked list
SD_DATA_RECEIVE_SHIFT_REGISTER
漫画 | 宇宙第一 IDE 到底是谁?
【分布式理论】(二)分布式存储
Toast will display a simple prompt message on the program interface
In depth understanding of USB communication protocol
Self made dataset in pytoch for dataset rewriting
Mobile app takeout ordering personal center page
【OKR目标管理】案例分析
随机推荐
科学家首次观察到“电子漩涡” 有助于设计出更高效的电子产品
深入浅出图解CNN-卷积神经网络
2021年全国平均工资出炉,你达标了吗?
Numberpick的功能和用法
Dragging the custom style of Baidu map to the right makes the global map longitude 0 unable to be displayed normally
带动画的列表选中js特效
Understanding of 12 methods of enterprise management
Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
[tpm2.0 principle and Application guide] Chapter 1-3
js拉下帷幕js特效显示层
Create dialog style windows with popupwindow
Functions and usage of ratingbar
Explain it in simple terms. CNN convolutional neural network
【解惑】App处于前台,Activity就不会被回收了?
本周小贴士#140:常量:安全习语
Robot engineering lifelong learning and work plan-2022-
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
Based on pytorch, we use CNN to classify our own data sets
Cartoon | who is the first ide in the universe?
在窗口上面显示进度条