目录
导入依赖:
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-jdbcartifactId>
- dependency>
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- /dependency>
记得配修改置项:
- spring:
- datasource:
- url: jdbc:mysql://localhost:3306/db_account
- username: root
- password: 123456
- driver-class-name: com.mysql.jdbc.Driver
测试:
- @SpringBootTest
- class Boot05WebAdminApplicationTests {
-
- @Autowired
- JdbcTemplate jdbcTemplate;
-
- @Test
- void contextLoads() {
-
- Long aLong = jdbcTemplate.queryForObject("select count(*) from account_tbl", Long.class);
- }
引入starter:
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>druid-spring-boot-starterartifactId>
- <version>1.1.17version>
- dependency>
配置示例:
- spring:
- datasource:
- url: jdbc:mysql://localhost:3306/db_account
- username: root
- password: 123456
- driver-class-name: com.mysql.jdbc.Driver
-
- druid:
- aop-patterns: com.atguigu.admin.* #监控SpringBean
- filters: stat,wall # 底层开启功能,stat(sql监控),wall(防火墙)
-
- stat-view-servlet: # 配置监控页功能
- enabled: true
- login-username: admin #进入后台的账号密码
- login-password: admin
- resetEnable: false
-
- web-stat-filter: # 监控web
- enabled: true
- urlPattern: /*
- exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
-
-
- filter:
- stat: # 对上面filters里面的stat的详细配置
- slow-sql-millis: 1000
- logSlowSql: true
- enabled: true
- wall:
- enabled: true
- config:
- drop-table-allow: false
druid后台访问地址:
http://localhost:8080/druid
引入starter:
- <dependency>
- <groupId>org.mybatis.spring.bootgroupId>
- <artifactId>mybatis-spring-boot-starterartifactId>
- <version>2.1.4version>
- dependency>
配置文件:
- # 配置mybatis规则
- mybatis:
- mapper-locations: classpath:mybatis/mapper/*.xml #mapper配置文件的位置
- configuration:
- map-underscore-to-camel-case: true
-
- #可以不写全局配置文件,所有全局配置文件的配置都放在configuration配置项中即可
建议安装 MybatisX 插件
引入starter,该starter已经包括了mybatis的配
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-redisartifactId>
- dependency>
置,无需再单独引入mybatis了:
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-boot-starterartifactId>
- <version>3.4.1version>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-redisartifactId>
- dependency>
切换至jedis:
-
- <dependency>
- <groupId>redis.clientsgroupId>
- <artifactId>jedisartifactId>
- dependency>
配置文件:
- spring:
- redis:
- host: xxxx
- port: xxxx
- password: xxxx
- client-type: jedis
- jedis:
- pool:
- max-active: 10