SpringBoot

// 启动类,位置必须高于其他类
@SpringBootApplication // 启动类注解
@MapperScan("com.itheima.mapper") // 指定mapper接口所在的包
@EnableAspectJAutoProxy // 开启aop
@ServletComponentScan
public class SpringBootDemoApplication {

    // springboot内置了tomcat,端口号默认8080 (约定大于配置)
    public static void main(String[] args) {
        // 固定写法
        // 参数一:启动类.class
        // 参数二:args
        SpringApplication.run(SpringBootDemoApplication.class, args);
    }
}

# 大小写敏感
# 缩进表示层级关系
# 参数值和冒号一定要有空格
# #代表注释
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springboot
    username: root
    password: 1234

mybatis:
  configuration:
    #    开启驼峰映射
    map-underscore-to-camel-case: true

# 日志级别( debug info warn error )
logging:
  level:
    com.itheima: info
  file:
    name: D:\\spring.log

# 只允许本地IP访问
server:
  address: 127.0.0.1

# 大小写敏感
# 缩进表示层级关系
# 参数值和冒号一定要有空格
# #代表注释
server:
  port: 8081
  servlet:
    context-path: /itheima

# 对象:键值对的集合
user:
  username: '张三'
  password: '123456'
  addressList: # 数组:固定写法
    - '杭州'
    - '北京'
    - '上海'

@RestController
public class IndexController {

     // @Value("${配置路径}"):读取配置
     @Value("${user.username}")
    private String username;
    @Value("${user.password}")
     private String password;

    @GetMapping("/index")
    public String index() {


        return "hello spring boot";
    }

}

@Data
@Configuration // 配置类
@ConfigurationProperties(prefix = "user") // 读取配置文件中指定配置
public class UserConfig {
    private String username;
    private String password;
    private List<String> addressList;
}

@RestController
public class FileController {
    @Autowired
    private OssTemplate ossTemplate;

    // 文件上传
    @PostMapping("/upload")
    public Result uploadFile(MultipartFile image) throws IOException {
        // 调用阿里云工具类上传文件
        String filePath = ossTemplate.upload(image.getOriginalFilename(), image.getInputStream());
        // 返回文件路径
        return Result.success(filePath);
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值