讀取遠程服務(wù)器上的圖片在頁面上展示

開發(fā)環(huán)境

  • JDK:java8
  • IDE:IDEA
  • 項目框架:SpringBoot

項目配置

  1. application.yml配置
server:
  port: 6389
  ssl:
    key-store: .keystore
    key-store-type: JKS
    key-alias: alias
    key-store-password: xxxxxxxx
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/xxxxxxx?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: XXXXXX
    password: XXXXXX
#    password: root
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
logging:
  path: /opt/modules/logs/qrcode/qrcode.log
file:
  imageWidth: 80  #二維碼logo的寬度
  imageHeight: 80  #二維碼logo的高度
  QRCODE_SIZE: 400  #二維碼尺寸
  logoImagePath: /opt/modules/qrcode/logo/logo.png  #二維碼logo路徑
#  logoImagePath: D:/data/qrcode/logo.png  #二維碼logo路徑
  qrFilePath: /opt/modules/qrcode/  #生成二維碼路徑
#  qrFilePath: D:/data/qrcode/  #生成二維碼路徑
  imagesPath: file:/opt/modules/qrcode/  # 二維碼圖片映射路徑
#  imagesPath: file:D:/data/qrcode/  # 二維碼圖片映射路徑
  imageReturnPath: /images/**
  1. 靜態(tài)資源映射(圖片)
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by Tomthy on 2018/11/21.
 */
@Configuration
public class WebMvcConf extends WebMvcConfigurerAdapter {

    @Value("${file.imageReturnPath}")
    private String imageReturnPath;
    @Value("${file.imagesPath}")
    private String imagesPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //imageReturnPath:映射前綴,imagesPath:圖片映射路徑
        registry.addResourceHandler(imageReturnPath).addResourceLocations(imagesPath);
    }
}
  1. 本地圖片地址


    image.png
  2. url請求查詢


    image.png

服務(wù)器與本地使用情況相同

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容