IDEA IDEA Plugins Mybatis

1、在IDEA安装Easy Code插件

image.png

2、在IDEA中使用DateBase连接数据库

参考
语雀内容

3、生成逆向工程的代码

A.选择逆向的表结构

image.png

B.配置逆向生成的路径

image.png

C.提示创建不存在的包路径

image.png

D.逆向生成的分层

image.png

E.Dao层添加 @Mapper 注解

image.png

F.启动类添加 @MapperScan 注解进行Dao层接口扫描

image.png

G.在配置文件配置数据源信息-此处使用阿里的Druid数据源管理

①Druid的依赖

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>druid-spring-boot-starter</artifactId>
  4. <version>1.1.13</version>
  5. </dependency>

②数据源配置

  1. mysql:
  2. url: jdbc:mysql:///test?serverTimezone=UTC
  3. username: root
  4. password: 123456
  5. driverClassName: com.mysql.cj.jdbc.Driver
  6. spring:
  7. application:
  8. name: ServiceActiviti
  9. datasource:
  10. type: com.alibaba.druid.pool.DruidDataSource
  11. url: ${mysql.url}
  12. driver-class-name: ${mysql.driverClassName}
  13. username: ${mysql.username}
  14. password: ${mysql.password}
  15. druid: # #
  16. url: ${mysql.url}
  17. username: ${mysql.username}
  18. password: ${mysql.password}
  19. driver-class-name: ${mysql.driverClassName}
  20. initial-size: 10
  21. max-active: 200
  22. min-idle: 10
  23. max-wait: 60000
  24. pool-prepared-statements: false
  25. validation-query: SELECT 1 FROM DUAL
  26. test-on-borrow: false
  27. test-on-return: false
  28. test-while-idle: true
  29. time-between-eviction-runs-millis: 60000
  30. min-evictable-idle-time-millis: 30000
  31. max-pool-prepared-statement-per-connection-size: 20
  32. aop-patterns: com.msyyt.crm.activity.*
  33. filter: # 状态监控
  34. stat:
  35. enabled: true
  36. db-type: mysql
  37. log-slow-sql: true
  38. slow-sql-millis: 2000
  39. web-stat-filter: # 监控过滤器
  40. enabled: true #是否启用 默认true
  41. exclusions:
  42. - '*.js'
  43. - '*.gif'
  44. - '*.jpg'
  45. - '*.png'
  46. - '*.css'
  47. - '*.ico'
  48. - /druid/*
  49. stat-view-servlet: # druid 监控页面
  50. enabled: true
  51. url-pattern: /druid/*
  52. reset-enable: false
  53. allow: # 白名单
  54. deny: # 黑名单
  55. login-username: admin
  56. login-password: admin
  57. mybatis:
  58. mapper-locations: classpath:/mapper/*Dao.xml
  59. typeAliasesPackage: com.vue.demo.entity

H.启动项目,使用HTTP Client成功访问接口

image.png