世间事,除了生死,哪一件不是闲事。——仓央嘉措《地空》
hutool
操作数据库这块可以看官方文档:
这里做个简单演示:例如select * from user
GAV
一导
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <dependencies> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.22</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </dependency> </dependencies>
|
代码一写:
1 2
| List<Entity> query = Db.use(new SimpleDataSource("jdbc:mysql://localhost:3306/test?autoReconnect=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useUnicode=true&characterEncoding=utf-8&useSSL=false&nullCatalogMeansCurrent=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true&allowPublicKeyRetrieval=true", "root", "root")).query("select * from user"); System.out.println(query);
|
完成