企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### 数据访问层,在sc-core这个模块中,和普通的SpringBoot工程一致 - 配置文件 application.yml ``` spring: datasource: druid: driver-class-name: com.mysql.jdbc.Driver connection-init-sqls: set names utf8mb4 url: jdbc:mysql://localhost:3306/dgsc?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true type: com.alibaba.druid.pool.DruidDataSource username: root password: 123456 ``` - pom文件引入依赖 ``` <!--springboot 集成Mybatis所需jar配置 start --> <!--支持使用 JDBC 访问数据库 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> <exclusions> <exclusion> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </exclusion> </exclusions> </dependency> <!--mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.1.0</version> <exclusions> <exclusion> <artifactId>mybatis-spring-boot-starter</artifactId> <groupId>org.mybatis.spring.boot</groupId> </exclusion> </exclusions> </dependency> <!--pagehelper--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency> <!--mysql--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--druid依赖添加--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <!--springboot 集成Mybatis所需jar配置 end --> ``` - 其他和普通项目差不多了 - 测试Bean ![](https://box.kancloud.cn/bd613b000ba9fa96d0484f174a290e0a_371x254.png) - mapper接口类 ![](https://box.kancloud.cn/aaef7dc5e97829bea384e1127b28cfc7_555x180.png) - service 类 ![](https://box.kancloud.cn/0640d1c10176c6b869e8544a61e24ae0_589x311.png) - 最后在Controller类进行测试 ![](https://box.kancloud.cn/20fec3de82b4f20fbcacc451dc225fb5_426x383.png) - postman测试插入成功 ![](https://box.kancloud.cn/d78a07e6994a78270a4bc278c3792129_934x502.png) - 数据库可以看到插入成功 ![](https://box.kancloud.cn/92d0917fb8ac39527d0b6679797c5979_451x95.png)