package com.java1234.miaosha.config;
import com.java1234.miaosha.interceptor.SysInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE","OPTIONS")
.maxAge(3600);
}
public SysInterceptor sysInterceptor(){
return new SysInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
String[] patterns=new String[]{"/login"};
registry.addInterceptor(sysInterceptor())
.addPathPatterns("/**")
.excludePathPatterns(patterns);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/image/**").addResourceLocations("file:D:\\miaoshaimg\\");
}
}
<el-table-column
prop="goods.image"
label="商品图片"
width="180">
<template slot-scope="scope">
<img :src="getSrcUrl(scope.row.goods.image)" width="60" height="80"/>
</template>
</el-table-column>
methods: {
getSrcUrl(t) {
return getServerUrl('image/' + t);
},
export function getServerUrl(url){
return "http://localhost:80/"+url;
}