Răsfoiți Sursa

http status 301

deason 6 ani în urmă
părinte
comite
3683ca98ce

+ 1 - 1
src/main/java/cn/com/qmth/examcloud/app/controller/version1/OfflineExamController.java

@@ -83,7 +83,7 @@ public class OfflineExamController {
     @ApiOperation(value = "下载考题接口")
     @RequestMapping(value = "/paper/download", method = {RequestMethod.GET})
     public String downloadPaper(@RequestParam String paperId, @RequestParam String orgName) throws Exception {
-        String requestUrl = "redirect:" + questionPoolService.downloadPaper(paperId, orgName);
+        String requestUrl = "redirectPermanent:" + questionPoolService.downloadPaper(paperId, orgName);
         log.debug(requestUrl);
         return requestUrl;
     }

+ 39 - 0
src/main/java/cn/com/qmth/examcloud/app/core/config/RedirectViewResolver.java

@@ -0,0 +1,39 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-08-21 17:51:26.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.app.core.config;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.View;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.view.RedirectView;
+
+import java.util.Locale;
+
+/**
+ * Resolver HTTP STATUS 301
+ *
+ * @author: fengdesheng
+ * @since: 2018/8/21
+ */
+@Component
+public class RedirectViewResolver implements ViewResolver {
+    public static final String REDIRECT_PERMANENT_PREFIX = "redirectPermanent:";
+
+    @Override
+    public View resolveViewName(String viewName, Locale locale) throws Exception {
+        if (viewName.startsWith(REDIRECT_PERMANENT_PREFIX)) {
+            String redirectUrl = viewName.substring(REDIRECT_PERMANENT_PREFIX.length());
+            RedirectView view = new RedirectView(redirectUrl);
+            view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
+            return view;
+        }
+        return null;
+    }
+
+}