hutool-db

2022-08-21 12:50:25 浏览数 (1)

hutool操作数据库这块可以看官方文档:

这里做个简单演示:例如select * from user

GAV一导

代码语言:javascript复制
<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>

代码一写:

代码语言:javascript复制
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);

完成

0 人点赞