使用SpringBoot+MyBatis+MySQL实现图片上传

一、技术参数:

SpringBoot 1.15.6.RELEASE

MyBatis-SpringBoot 1.3.2

MySQL 5.1.30

数据库连接池:druid

Maven 3.5.9

项目pom文件:



    4.0.0
 
    fileupload
    demo
    0.0.1-SNAPSHOT
    jar
 
    demo
    Demo project for Spring Boot
 
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.16.RELEASE
         
    
 
    
        UTF-8
        UTF-8
        1.8
    
 
    
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
 
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
 
        
            
            
        
 
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
 
        
            mysql
            mysql-connector-java
            5.1.30
            
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
 
        
            com.alibaba
            druid
            1.0.11
        
        
            com.fasterxml.jackson.core
            jackson-core
        
        
            com.fasterxml.jackson.core
            jackson-databind
        
        
            com.fasterxml.jackson.datatype
            jackson-datatype-joda
        
        
            com.fasterxml.jackson.module
            jackson-module-parameter-names
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.1.2
        
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.0
        
 
 
        
            com.google.guava
            guava
            20.0
        
 
 
        
            org.apache.commons
            commons-lang3
            3.5
        
 
 
        
            commons-collections
            commons-collections
            3.2.1
        
 
    
 
 
 
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
 
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2                
                ${basedir}/src/main/resources/generatorConfig.xml
                true
                true
            
            
        
    
 
 

二、项目配置文件application.yml

server:
  port: 8086
#FreeMarker
pring:
  freemarker:
    allow-request-override: false
    cache: false
    check-template-location: true
    charset: UTF-8
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false
    suffix: .ftl
spring:
    datasource:
       name: test
       url: jdbc:mysql://127.0.0.1:3306/springBootDemo
       username: root
       password: root
       # 使用druid数据源
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.jdbc.Driver
       filters: stat
       maxActive: 20
       initialSize: 1
       maxWait: 60000
       minIdle: 1
       timeBetweenEvictionRunsMillis: 60000
       minEvictableIdleTimeMillis: 300000
       validationQuery: select 'x'
       testWhileIdle: true
       testOnBorrow: false
       testOnReturn: false
       poolPreparedStatements: true
       maxOpenPreparedStatements: 20
 
 
mybatis:
  mapper-locations: classpath:mapping/*.xml
  type-aliases-package: com.winter.model
 
 
#pagehelper分页插件
pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql
 
 
##上传图片保存的路径
#img:
#  location: /Downloads/imgUpload/
 
#配置上传文件的最大值
servlet:
  multipart:
    max-file-size: 5Mb
    max-request-size: 50Mb
 
#自定义文件上传路径
web:
  upload-path: /Downloads/imgUpload/

三、项目说明

1、项目默认将图片上传到本地路径,如果需要上传到服务器路径直接在项目中进行修改即可,不要忘了修改存储到数据库中的路径。

2、项目没有使用任何图片上传控件或插件,原生springBoot实现,简单易上手。

3、项目使用Maven进行构建,朋友们在导入项目时不要导错了。

四、项目开源地址https://github.com/SteafanMrZhou/springBootPractice如有不懂的地方可以随时留言,我会及时为大家解决,谢谢大家关注!
 

原文:https://blog.csdn.net/qq_36314960/article/details/83010010 

你可能感兴趣的:(后端开发,图片上传)