当前位置:   article > 正文

springboot整合mybatis_springboot 2.3.12 mybatis 配置

springboot 2.3.12 mybatis 配置

(1)相关依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.3.12.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.tm</groupId>
  12. <artifactId>springboot</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>springboot</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-web</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>mysql</groupId>
  26. <artifactId>mysql-connector-java</artifactId>
  27. </dependency>
  28. <!--mybatis和springboot整合的依赖 启动依赖-->
  29. <dependency>
  30. <groupId>org.mybatis.spring.boot</groupId>
  31. <artifactId>mybatis-spring-boot-starter</artifactId>
  32. <version>2.1.4</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>com.alibaba</groupId>
  36. <artifactId>druid-spring-boot-starter</artifactId>
  37. <version>1.1.21</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.projectlombok</groupId>
  41. <artifactId>lombok</artifactId>
  42. <optional>true</optional>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework.boot</groupId>
  46. <artifactId>spring-boot-starter-test</artifactId>
  47. <scope>test</scope>
  48. </dependency>
  49. </dependencies>
  50. <build>
  51. <plugins>
  52. <plugin>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-maven-plugin</artifactId>
  55. <configuration>
  56. <excludes>
  57. <exclude>
  58. <groupId>org.projectlombok</groupId>
  59. <artifactId>lombok</artifactId>
  60. </exclude>
  61. </excludes>
  62. </configuration>
  63. </plugin>
  64. </plugins>
  65. </build>
  66. </project>

(2)修改配置文件

  1. #数据源
  2. spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver
  3. spring.datasource.druid.username=root
  4. spring.datasource.druid.password=123456
  5. spring.datasource.druid.url=jdbc:mysql://localhost:3306/db1
  6. #指定映射文件所在的路径--
  7. mybatis.mapper-locations=classpath:mapper/*.xml
  8. #mybatis日志文件
  9. mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

(3) mapper接口

(4)为mapper接口生成代理实现类

(5)测试

使用springboot整合mybatis 完成crud

具体代码在码云仓库中

网址  tm0411: 20230411作业

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/498207
推荐阅读
相关标签
  

闽ICP备14008679号