当前位置: 首页 > news >正文

零基础 网站岳阳seo公司

零基础 网站,岳阳seo公司,深圳微信网站开发,java web医疗网站开发服务类 系统盘符:file-path.disk(可能会变,配置配置文件dev中)文件根路径:file-path.root-path(可能会变,配置配置文件dev中)http协议的Nginx的映射前缀:PrefixConstant.…

服务类

  • 系统盘符:file-path.disk(可能会变,配置配置文件dev中)
  • 文件根路径:file-path.root-path(可能会变,配置配置文件dev中)
  • http协议的Nginx的映射前缀:PrefixConstant.HTTP_PREFIX
package com.sky.service;import com.sky.constant.MessageConstant;
import com.sky.constant.PrefixConstant;
import com.sky.exception.BaseException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.IOException;@Service
public class CommonService {@Value("${file-path.disk}")private String disk;@Value("${file-path.root-path}")private String rootPath;/*** 文件上传** @param parentPath 父路径* @param file       文件*/public String upload(String parentPath, MultipartFile file) {// Upload fileString fileName = file.getOriginalFilename();// Get full path using system file separatorString fullPath = disk + ":" + File.separator + rootPath + File.separator + parentPath;// Create the directory if it doesn't existFile directory = new File(fullPath);if (!directory.exists()) {directory.mkdirs();}// Create the destination fileFile dest = new File(directory, fileName);try {file.transferTo(dest);} catch (IOException e) {throw new BaseException(MessageConstant.UPLOAD_FAILED);}// Return the file access URLreturn PrefixConstant.HTTP_PREFIX +fileName;}
}

配置文件

在这里插入图片描述

总配置文件

sky:jwt:# 设置jwt签名加密时使用的秘钥admin-secret-key: itcast# 设置jwt过期时间admin-ttl: 720000000# 设置前端传递过来的令牌名称admin-token-name: tokenfile-path:disk: ${file-path.disk}root-path: ${file-path.root-path}

开发环境配置文件

file-path:disk: Droot-path: sky_take_out

常量类

在这里插入图片描述

文件路径常量

package com.sky.constant;public class SystemPathConstant {public static final String COMMON = "common";// 构造函数私有化private SystemPathConstant() {}
}

nginx路径映射常量

package com.sky.constant;public class PrefixConstant {public static final String HTTP_PREFIX = "http://localhost/files/";// 构造函数私有化private PrefixConstant() {}
}

controller层

别人上传完图片之后把访问路径给别人(http的路径,不是本地路径)

    @PostMapping("/upload")@ApiOperation("文件上传")public Result<String> upload(MultipartFile file) {log.info("文件上传:{}", file);// 将文件上传到本地文件夹下// 返回文件的访问路径String filePath = commonService.upload(SystemPathConstant.COMMON,file);return Result.success(filePath);}

配置类放行静态资源

package com.sky.config;import com.sky.constant.SystemPathConstant;
import com.sky.interceptor.JwtTokenAdminInterceptor;
import com.sky.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;import java.util.List;/*** 配置类,注册web层相关组件*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {@Autowiredprivate JwtTokenAdminInterceptor jwtTokenAdminInterceptor;@Value("${file-path.disk}")private String disk;@Value("${file-path.root-path}")private String rootPath;..... 其他配置一万行/*** 设置静态资源映射* @param registry*/protected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");// Map the file directory to a URL pathregistry.addResourceHandler("/files/**").addResourceLocations("file:" +disk + ":" + "/" +rootPath + "/" +SystemPathConstant.COMMON + "/");}}

nginx映射

静态资源到本地盘符(这就你的代码中配置的判读)

  • 这个文件是开发环境的,正式环境按照正式环境的路径和盘符配置
    改完记得重启一下
       location /files/ {alias D:/sky_take_out/common/;}
  • 有的时候会访问403 异常
  • 文件权限异常
  • 访问一定要访问具体文件,不要访问到文件夹
    在这里插入图片描述
http://www.tj-hxxt.cn/news/115978.html

相关文章:

  • 网站 创意 方案二级域名在线扫描
  • 南京网站搭建淘宝运营培训班学费大概多少
  • 和网站建设相关的行业柳州今日头条新闻
  • 可以做长页的网站最简单的营销方案
  • 故城网站建设嵌入式培训机构哪家好
  • 济宁 做网站百度软文
  • 平台与网站有什么区别网络营销的方式有十种
  • o2o网站建设哪家好百度站长工具使用方法
  • 设计网站公司可去亿企邦关键词在线优化
  • 丽水网站建设哪家好制作网站的最大公司
  • 网站建设 陕icp职业培训热门行业
  • wordpress 左侧浮动无线网络优化工程师
  • 建设医院网站的重点与难点在于网站推广优化公司
  • 西安互联网品牌搭建简阳seo排名优化课程
  • 怎么建设QQ网站seo相关岗位
  • 开发网站要注意什么百度站长平台app
  • wordpress 比特币行情seo入口
  • 嘉兴网站推广公司产品营销方案策划
  • 百度做网站多少钱能做seo博客优化
  • 婚纱网站页面设计公司网站模板设计
  • 有了ddns怎么建设网站百度一下百度搜索
  • 整站wordpress下载百度推广费用可以退吗
  • 武汉做网站方式网站建设报价明细表
  • 上海工厂网站建设网站宣传推广策划
  • 浦江网站建设项目营销推广策划
  • 自学做衣服的网站百度推广费2800元每年都有吗
  • 政务网站源码google浏览器官方
  • 连州网站建设西安seo和网络推广
  • 用花瓣网站上的图片做游戏行吗专业关键词排名软件
  • 桂林市天气预报15天准确seo合作