spring boot笔记()

1、Profile

#application-dev.properties开发环境
#application-prod.properties生产环境、
#application-test.properties测试环境

不同的属性就放到不同的文件中去,公共的属性放在application.properties中就可以了。
需要哪一个环境在application.properties配置spring.profiles.active=dev。
在这里插入图片描述

2、静态资源访问

默认静态资源路径
在resources下的static文件夹下
修改静态资源路径
spring.resources.static-locations=classpath:/文件夹/

3、restful风格传参

在这里插入图片描述

 @GetMapping("/list1/{id}")
    public List<Map<String, Object>> userList1(@PathVariable("id") int id){
        String sql ="select * from user where id = ?";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql,id);
        return maps;

4、springboot整合jdbc与druid的使用

Spring Boot 2.0 以上默认使用 Hikari 数据源,
jdbc传送门
druid使用
添加依赖

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.22</version>
        </dependency>

在配置文件中添加

spring:
  datasource:
    username: root
    password: 111111
    url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource #自定义数据源

druid还可以用于日志监控等一些操作,这里不做叙述,可以参考
druid传送门

猜你喜欢

转载自blog.csdn.net/weixin_42072357/article/details/105762171