chao vor 4 Jahren
Ursprung
Commit
b0b700088d

+ 27 - 0
src/main/java/com/caimei/www/config/CustomExceptionHandler.java

@@ -0,0 +1,27 @@
+package com.caimei.www.config;
+
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import reactor.core.publisher.Mono;
+
+/**
+ * 统一异常处理
+ *
+ * @author : Charles
+ * @date : 2020/8/7
+ */
+@RestControllerAdvice
+public class CustomExceptionHandler {
+
+    @ExceptionHandler(Exception.class)
+    public String convertExceptionMsg(Exception e){
+        //自定义逻辑,可返回其他值
+        return "404";
+    }
+
+    @ExceptionHandler(IllegalAccessException.class)
+    public Mono<String> convertIllegalAccessError(Exception e){
+        //自定义逻辑,可返回其他值
+        return Mono.just("illegal access");
+    }
+}

+ 11 - 9
src/main/java/com/caimei/www/config/CustomWebFilter.java

@@ -14,14 +14,16 @@ import reactor.core.publisher.Mono;
  */
 @Component
 public class CustomWebFilter implements WebFilter {
-  @Override
-  public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
-    if ("/".equals(exchange.getRequest().getURI().getPath())) {
-        return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build()).build());
-    }
-    if ("/favicon.ico".equals(exchange.getRequest().getURI().getPath())) {
-        return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/favicon.ico").build()).build());
+
+    @Override
+    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
+        if ("/".equals(exchange.getRequest().getURI().getPath())) {
+            return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build()).build());
+        }
+        Mono<Void> response = chain.filter(exchange);
+        return response;
     }
-    return chain.filter(exchange);
-  }
+
+
+
 }

+ 23 - 0
src/main/java/com/caimei/www/config/StaticRoute.java

@@ -0,0 +1,23 @@
+package com.caimei.www.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.web.reactive.function.server.RouterFunction;
+import org.springframework.web.reactive.function.server.RouterFunctions;
+import org.springframework.web.reactive.function.server.ServerResponse;
+
+/**
+ * 静态资源路径
+ *
+ * @author : Charles
+ * @date : 2020/8/7
+ */
+@Configuration
+public class StaticRoute {
+    @Bean
+    RouterFunction<ServerResponse> staticResourceRouter(){
+        return RouterFunctions.resources("/static/**",
+                new ClassPathResource("static/"));
+    }
+}

BIN
src/main/resources/public/favicon.ico


BIN
src/main/resources/static/favicon.ico


BIN
src/main/resources/static/img/favicon.ico


+ 1 - 2
src/main/resources/templates/components/head-link.html

@@ -5,8 +5,7 @@
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <meta http-equiv="keywords" content="采美、易耗品商城、光电美容仪器项目、光电中心、皮肤管理中心、光电转型、美容院转型、光电美容">
     <meta http-equiv="description" content="采美365网——中国美业互联网共享经济平台,中国美业较大的光电美容干货信息平台,提供美容专业线客装产品、美容院消耗品、专业线院装产品、光电美容仪器、光电美容项目交易,同时提供采美公益大讲堂、光电美容干货、光电美容资讯、美业动态等行业信息。采集梦想,美启未来。">
-    <link rel="shortcut icon" th:href="@{/favicon.ico}" type="image/x-icon">
-    <link rel="bookmark" th:href="@{/favicon.ico}" type="image/x-icon">
+    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
     <link href="/lib/swiper.min.css" media="screen and (max-width:768px)" rel="stylesheet" type="text/css">
     <link href="/lib/jquery-confirm.min.css" rel="stylesheet" type="text/css">
     <link th:href="@{/css/base/init.css(v=${version})}" rel="stylesheet" type="text/css">