前后分离项目,前端展示服务器上面的图片

1、创建webcofig,如图

package net.dgjy.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ Author     :johnbarrowman65
 * @ Date       :Created in 11:06 2019/8/15
 * @ Description:
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 在D:/res/pic下如果有一张 luffy.jpg.jpg的图片,那么:
    // 1 访问:http://localhost:8080/img/luffy.jpg 可以访问到
    // 2 html 中 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:G:/PicturePath/");
    }

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:/root/feedback/");
    }*/
}

2、前端代码

logo

你可能感兴趣的:(springboot)