文件上传和下载

本文详细介绍了Spring Boot项目的配置参数,包括服务器端口、数据源连接池、MyBatis配置等,同时展示了如何通过配置文件实现项目的高效运行,并提供了一个具体的控制器示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

server:
  port: 8080
  servlet:
    #项目访问名称
    context-path: /springboot
spring:
  mvc:
    #静态资源映射
    static-path-pattern: classpath:/statics/**
  resources:
    static-locations: /statics/
  datasource:
    url: jdbc:mysql://localhost:3306/appinfodb?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    #初始化大小
    initial-size: 5
    #最小值
    min-idle: 5
    #最大值
    max-active: 20
    #最大等待时间,配置获取连接等待超时,单位是毫秒
    max-wait: 60000
    #配置间隔多久进行一次检测,检测需要关闭的空闲连接
    time-between-eviction-runs-millis: 60000
    #配置一个连接在连接池中最小的生存时间
    min-evictable-idle-time-millis: 300000
    validation-query: SELECT 1 FROM DUAL
    test-while-idle: true
    test-on-borrow: false
    test-on-return: false
    pool-prepared-statements: true
    max-pool-prepared-statement-per-connection-size: 20
    #配置监控统计拦截的filters,去掉后监控界面的sql就无法统计了
    filters: stat,wall,log4j2
    use-global-data-source-stat: true
    connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
  thymeleaf:
    servlet:
      content-type: text/html
    cache: false
    encoding: UTF-8
    mode: LEGACYHTML5
    prefix: classpath:/templates/
    suffix: .html
    check-template-location: true
  redis:
    #Redis 数据库索引 默认0
    database: 0
    host: localhost
    port: 6379
    #password:
    jedis:
      pool:
        max-active: 100
        max-wait: 3000
        #连接池中最多空闲连接
        max-idle: 100
    timeout: 1000
  devtools:
    restart:
      enabled: true # 设置开启热部署
      additional-paths: src/main/java  #重启的目录
      exclude: templates/**
  freemarker:
    cache: false # 页面不加载缓存 ,修改立即生效
  servlet:
    multipart:
      max-request-size: 20MB # 设置上传文件总最大值
      max-file-size: 20MB # 单个文件最大值
logging:
  level:
    com.xl.mapper: debug
mybatis:
  type-aliases-package: com.xk.pojo
  mapper-locations: classpath:mapper/*.xml
  configuration: #显示SQL语句在控制台
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

controller.java

@RequestMapping(value="addAppinfoVersion",method=RequestMethod.POST)
public String addAppinfoVersion(@RequestParam("file")MultipartFile file,
								@ModelAtttribute("appVersion")AppVersion 			 
								appVersion,Model model){
    if(file.isEmptu(){
        model.addAttribute("error","上传失败,请选择文件");
        return "developer/appversionadd";
    })
    String fileName=file.getOriginalFilename();
    String filePath="D:\\...\\uploadfiles\\";
    File dest =new File(filePath+fileName);
    
    try{
        file.transferTo(dest);
    }catch(IOException e){
        e.printStackTrace();
    }
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值