zoukankan      html  css  js  c++  java
  • 图片服务映射(SpringBoot mybatis-plus)

    配置类

    package cn.edu.qfnu.soft.common.config;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    
    /**
     * 跨域配置
     * @author Louis
     * @date Jan 12, 2019
     */
    @Configuration
    public class CorsConfig  implements WebMvcConfigurer {
        /**
         * @author 吕嘉鸣
         * 配置图片服务映射
         * @param registry
         */
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/img/**").addResourceLocations("file:D:/photos/");
    
            registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        }
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")	// 允许跨域访问的路径
                    .allowedOrigins("*")	// 允许跨域访问的源
                    .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")	// 允许请求方法
                    .maxAge(168000)	// 预检间隔时间
                    .allowedHeaders("*")  // 允许头部设置
                    .allowCredentials(true);	// 是否发送cookie
        }
    }
    
    

    拼接映射访问路径

    @Override
        public String 拼接映射访问路径( HttpServletRequest request) {
    
            ChkBillImg chkBillImg = chkBillImgMapper.selectOne(queryWrapper);
    
            String httpUrl = chkBillImg.getUrl().replace("D:\photos\", "").replace("\", "/");
            try {
                    httpUrl = "101.201.148.143"+":"+String.valueOf(request.getServerPort())+ File.separator +"img"+File.separator+httpUrl;
                    httpUrl = "http://"+httpUrl.replace("\", "/");
                    chkBillImg.setUrl(httpUrl);
                } catch (SocketException e) {
                    e.printStackTrace();
                }
            return httpUrl;
        }
    
  • 相关阅读:
    react 安装脚手架过程
    微信小程序-分享功能
    echarts 实现多图联动显示tooltip
    dom 相同父节点查找
    js 给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果
    vue手写el-form组件
    vue组件传值、通信
    vue项目打包桌面应用 exe程序 以及打包为安装程序exe
    vue 使用echarts来制作图表
    前端数据可视化插件-图表
  • 原文地址:https://www.cnblogs.com/ideaAI/p/14745400.html
Copyright © 2011-2022 走看看