Java设置服务器图片

现做app需要用到图片,但不想放到app项目代码中,于是想到设置服务器图片,app中设置访问路径,加载图片,路径也可以设置为变量,方便变更

服务器代码添加类

package hs.hsapp.util;

import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration

public class ResourcesConfig implements WebMvcConfigurer {

@Override

public void addResourceHandlers(ResourceHandlerRegistry registry) {

/** 通过url访问项目外的目录图片*/

registry.addResourceHandler("/mgg/**").addResourceLocations("file:E://tmpimg/");

}}

创建本地目录e://tmpimg, 用于存放图片文件

mgg 访问路径, e://tmpimg图片物理路径

Security配置类 添加类型过滤
重启服务,访问测试

https://localhost: 8080/mgg/denglu.jpg

相关推荐
Wang's Blog5 小时前
Java 项目实战: 交友项目 - FastDFS:入门案例
java·开发语言·交友
apcipot_rain6 小时前
C++转Java日记(03)
java·开发语言·c++
皮皮林5516 小时前
Java实现微信扫码登录
java
布莱克6056 小时前
C++ 中 map 的 insert 与 emplace:key 已存在时会覆盖吗?
开发语言·数据结构·c++·算法·map
xys_6786 小时前
深挖C++:类和对象(中)
开发语言·c++
灿飞屋6 小时前
Rust 编程其实很简单
开发语言·rust
Yyyyyy~8 小时前
【Java】Day4Web基础知识
java·spring boot
MOONICK8 小时前
QT元数据
开发语言·qt
D e re k ZH9 小时前
C++ 系统学习手记:从语法细节到工程实践
开发语言·数据结构·c++·算法
灿飞屋9 小时前
Kotlin与Java虚拟机三:控制流
android·java·开发语言·后端·python·kotlin·安卓