david 2 лет назад
Родитель
Сommit
9e8511b887

+ 30 - 0
src/main/java/com/roma/romaapi/config/CorsConfig.java

@@ -0,0 +1,30 @@
+package com.roma.romaapi.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class CorsConfig implements WebMvcConfigurer {
+    /**
+     * 开启跨域
+     */
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 设置允许跨域的路由
+        registry.addMapping("/**")
+                // 设置允许跨域请求的域名
+                .allowedOriginPatterns("*")
+                // 是否允许证书(cookies)
+                .allowCredentials(true)
+                // 设置允许的方法
+                .allowedMethods("*")
+                // 跨域允许时间
+                .maxAge(3600);
+
+    }
+}

+ 2 - 2
src/main/java/com/roma/romaapi/config/KaptchaConfig.java

@@ -13,7 +13,7 @@ public class KaptchaConfig {
         //Properties类
         Properties properties = new Properties();
         // 图片边框
-        properties.setProperty("kaptcha.border", "yes");
+        properties.setProperty("kaptcha.border", "no");
         // 边框颜色
         properties.setProperty("kaptcha.border.color", "105,179,90");
         // 字体颜色
@@ -21,7 +21,7 @@ public class KaptchaConfig {
         // 图片宽
         properties.setProperty("kaptcha.image.width", "110");
         // 图片高
-        properties.setProperty("kaptcha.image.height", "40");
+        properties.setProperty("kaptcha.image.height", "38");
         // 字体大小
         properties.setProperty("kaptcha.textproducer.font.size", "30");
         // session key

+ 13 - 0
src/main/java/com/roma/romaapi/controller/ApiController.java

@@ -2,14 +2,18 @@ package com.roma.romaapi.controller;
 
 
 import com.roma.romaapi.service.CaptchaService;
+import jakarta.servlet.http.HttpServletResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 
 @RestController
+@CrossOrigin
 public class ApiController {
 
     @Autowired
@@ -19,4 +23,13 @@ public class ApiController {
     public Map<String, Object> loginVerifyCode() throws IOException {
         return captchaService.captchaCreator();
     }
+
+    // 登录系统
+    @RequestMapping("/api/login")
+    public Map login(){
+        System.out.print("aaa");
+        Map a = new HashMap();
+        a.put("aa", "dsadsa");
+        return  a;
+    }
 }

+ 2 - 0
src/main/java/com/roma/romaapi/controller/DbApiController.java

@@ -8,6 +8,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
 import java.util.Map;
 
 @RestController
+@CrossOrigin(origins = "*")
 public class DbApiController {
 
     @Autowired

+ 2 - 0
src/main/java/com/roma/romaapi/controller/PageController.java

@@ -3,6 +3,7 @@ package com.roma.romaapi.controller;
 import com.roma.romaapi.service.PageService;
 import com.roma.romaapi.utils.CustomResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -11,6 +12,7 @@ import java.util.List;
 import java.util.Map;
 
 @RestController
+@CrossOrigin(origins = "*")
 public class PageController {
 
     @Autowired