CHENYIZONG vor 6 Jahren
Ursprung
Commit
8082770f77

+ 28 - 16
src/main/java/com/example/hotel/config/CORSConfig.java

@@ -2,26 +2,38 @@ package com.example.hotel.config;
 
 
 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.config.annotation.CorsRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
 
 
-/**
- * @Author: chenyizong
- * @Date: 2020-02-29
- */
 @Configuration
 @Configuration
 public class CORSConfig {
 public class CORSConfig {
+    private static String[] originsVal = new String[]{
+            "localhost:8081",
+            "127.0.0.1:8081",
+            "127.0.0.1",
+            "localhost",
+            "172.19.144.143",
+            "172.19.144.143:8000"
+    };
 
 
     @Bean
     @Bean
-    public WebMvcConfigurer corsConfigurer(){
-        return new WebMvcConfigurer() {
-            @Override
-            public void addCorsMappings(CorsRegistry registry) {
-                registry.addMapping("/**")
-                        .allowedHeaders("*")
-                        .allowedMethods("*")
-                        .allowedOrigins("*");
-            }
-        };
+    public CorsFilter corsFilter() {
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        CorsConfiguration corsConfiguration = new CorsConfiguration();
+        addAllowedOrigins(corsConfiguration); // 1
+        //corsConfiguration.addAllowedOrigin("*");
+        corsConfiguration.addAllowedHeader("*"); // 2
+        corsConfiguration.addAllowedMethod("*"); // 3
+        corsConfiguration.setAllowCredentials(true); // 跨域session共享
+        source.registerCorsConfiguration("/**", corsConfiguration); // 4
+        return new CorsFilter(source);
+    }
+
+    private void addAllowedOrigins(CorsConfiguration corsConfiguration) {
+        for (String origin : originsVal) {
+            corsConfiguration.addAllowedOrigin("http://" + origin);
+            corsConfiguration.addAllowedOrigin("https://" + origin);
+        }
     }
     }
 }
 }

+ 3 - 2
src/main/java/com/example/hotel/controller/user/AccountController.java

@@ -2,8 +2,6 @@ package com.example.hotel.controller.user;
 
 
 import com.example.hotel.blImpl.user.AccountServiceImpl;
 import com.example.hotel.blImpl.user.AccountServiceImpl;
 import com.example.hotel.config.InterceptorConfiguration;
 import com.example.hotel.config.InterceptorConfiguration;
-import com.example.hotel.po.Hotel;
-import com.example.hotel.vo.OrderVO;
 import com.example.hotel.vo.UserForm;
 import com.example.hotel.vo.UserForm;
 import com.example.hotel.vo.ResponseVO;
 import com.example.hotel.vo.ResponseVO;
 import com.example.hotel.vo.UserVO;
 import com.example.hotel.vo.UserVO;
@@ -42,4 +40,7 @@ public class AccountController {
         return "index";
         return "index";
     }
     }
 
 
+//    @GetMapping("/usertype")
+//    public String getUserType()
+
 }
 }

+ 2 - 2
src/main/java/com/example/hotel/data/user/AccountMapper.java

@@ -20,8 +20,8 @@ public interface AccountMapper {
 
 
     /**
     /**
      * 根据用户名查找账号
      * 根据用户名查找账号
-     * @param username
+     * @param email
      * @return
      * @return
      */
      */
-    public UserVO getAccountByName(@Param("username") String username);
+    public UserVO getAccountByName(@Param("email") String email);
 }
 }

+ 18 - 0
src/main/java/com/example/hotel/enums/UserType.java

@@ -0,0 +1,18 @@
+package com.example.hotel.enums;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+public enum UserType {
+    Client(1),
+    HotelManager(2),
+    Manager(3);
+    private int value;
+
+    UserType(int value) {
+        this.value = value;
+    }
+
+
+}

+ 12 - 0
src/main/java/com/example/hotel/vo/UserForm.java

@@ -14,6 +14,10 @@ public class UserForm {
      */
      */
     private String password;
     private String password;
 
 
+
+    private String userType;
+
+
     public String getEmail() {
     public String getEmail() {
         return email;
         return email;
     }
     }
@@ -29,4 +33,12 @@ public class UserForm {
     public void setPassword(String password) {
     public void setPassword(String password) {
         this.password = password;
         this.password = password;
     }
     }
+
+    public String getUserType() {
+        return userType;
+    }
+
+    public void setUserType(String userType) {
+        this.userType = userType;
+    }
 }
 }