1.文件上传增加后缀名校验

2.token拦截器撤销注释
This commit is contained in:
zty 2024-10-16 16:44:23 +08:00
parent fe9fbd8992
commit 18aff440ee
3 changed files with 30 additions and 20 deletions

View File

@ -1,18 +1,19 @@
package com.xqopen.kehui.conf; package com.xqopen.kehui.conf;
import java.util.Locale; import com.xqopen.kehui.interceptor.PermissionInterceptor;
import com.xqopen.kehui.util.Constants; import com.xqopen.kehui.util.Constants;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry; 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.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver; import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import java.util.Locale;
@Configuration @Configuration
public class WebMVCConfig extends WebMvcConfigurerAdapter { public class WebMVCConfig extends WebMvcConfigurerAdapter {
@ -45,14 +46,14 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter {
return lci; return lci;
} }
// @Override @Override
// public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
// //国际化过滤器 //国际化过滤器
// registry.addInterceptor(localeChangeInterceptor()); registry.addInterceptor(localeChangeInterceptor());
// //自定义拦截器 //自定义拦截器
// registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**"); registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**");
// super.addInterceptors(registry); super.addInterceptors(registry);
// } }
/** /**
* 静态文件处理 * 静态文件处理

View File

@ -1,18 +1,16 @@
package com.xqopen.kehui.util; package com.xqopen.kehui.util;
import static com.xqopen.kehui.util.Constants.LINE_SEPARATOR; import com.xqopen.kehui.common.dto.FileItem;
import com.xqopen.kehui.exception.ErrorCode;
import com.xqopen.kehui.exception.XQException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import com.xqopen.kehui.common.dto.FileItem; import static com.xqopen.kehui.util.Constants.LINE_SEPARATOR;
import com.xqopen.kehui.exception.ErrorCode;
import com.xqopen.kehui.exception.XQException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
@Slf4j @Slf4j
public class FileUploadUtil { public class FileUploadUtil {
@ -22,6 +20,11 @@ public class FileUploadUtil {
if (file.isEmpty()) { if (file.isEmpty()) {
throw new XQException(ErrorCode.UPLOAD_FILE_EMPTY, null); throw new XQException(ErrorCode.UPLOAD_FILE_EMPTY, null);
} }
String filename = file.getOriginalFilename();
//后缀名固定
if(!(filename.endsWith(".jpg")||filename.endsWith(".png")||filename.endsWith(".jpeg")||filename.endsWith(".pdf")||filename.endsWith(".docx")||filename.endsWith(".doc"))){
throw new XQException(ErrorCode.UPLOAD_FILE_ERORR, null);
}
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String originalFileName = file.getOriginalFilename(); String originalFileName = file.getOriginalFilename();

View File

@ -4,7 +4,13 @@ spring:
# url: jdbc:postgresql://ali4.xqopen.com:30390/kehui # url: jdbc:postgresql://ali4.xqopen.com:30390/kehui
url: jdbc:postgresql://localhost:5432/kehui url: jdbc:postgresql://localhost:5432/kehui
username: postgres username: postgres
password: admin password: 123456
# url: jdbc:postgresql://8.131.55.216/kehui
# username: postgres
# password: 8zysGtJGDCPdkXya
# url: jdbc:postgresql://localhost:5432/kehui
# username: postgres
# password: admin
#自定义系统属性 #自定义系统属性
attach: attach: