xiangpei
2024-05-16 9654776025968dcc4c9e41ee7b6578d72bbf9b43
统一相应类重构
3个文件已修改
86 ■■■■■ 已修改文件
src/main/java/com/mindskip/xzs/base/RestResponse.java 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/configuration/spring/security/RestUtil.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/configuration/spring/security/SecurityConfigurer.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/base/RestResponse.java
@@ -15,8 +15,8 @@
     * @param message the message
     */
    public RestResponse(int code, String message) {
        this.code = code;
        this.message = message;
        this.put("code", code);
        this.put("message", message);
    }
    /**
@@ -26,10 +26,12 @@
     * @param message  the message
     * @param response the response
     */
    public RestResponse(int code, String message, T response) {
        this.code = code;
        this.message = message;
        this.response = response;
    public static RestResponse response(int code, String message, Object response) {
        RestResponse restResponse = new RestResponse();
        restResponse.put("code", code);
        restResponse.put("message", message);
        restResponse.put("response", response);
        return restResponse;
    }
    /**
@@ -62,7 +64,7 @@
     */
    public static <F> RestResponse<F> ok(F response) {
        SystemCode systemCode = SystemCode.OK;
        return new RestResponse<>(systemCode.getCode(), systemCode.getMessage(), response);
        return RestResponse.response(systemCode.getCode(), systemCode.getMessage(), response);
    }
    /**
@@ -71,16 +73,7 @@
     * @return the code
     */
    public int getCode() {
        return code;
    }
    /**
     * Sets code.
     *
     * @param code the code
     */
    public void setCode(int code) {
        this.code = code;
        return (int) this.get("code");
    }
    /**
@@ -89,17 +82,9 @@
     * @return the message
     */
    public String getMessage() {
        return message;
        return (String) this.get("message");
    }
    /**
     * Sets message.
     *
     * @param message the message
     */
    public void setMessage(String message) {
        this.message = message;
    }
    /**
     * Gets response.
@@ -107,16 +92,7 @@
     * @return the response
     */
    public T getResponse() {
        return response;
    }
    /**
     * Sets response.
     *
     * @param response the response
     */
    public void setResponse(T response) {
        this.response = response;
        return (T) this.get("response");
    }
    public RestResponse() {
src/main/java/com/mindskip/xzs/configuration/spring/security/RestUtil.java
@@ -52,7 +52,7 @@
     */
    public static void response(HttpServletResponse response, int systemCode, String msg, Object content) {
        try {
            RestResponse res = new RestResponse<>(systemCode, msg, content);
            RestResponse res = RestResponse.response(systemCode, msg, content);
            String resStr = JsonUtil.toJsonStr(res);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(resStr);
src/main/java/com/mindskip/xzs/configuration/spring/security/SecurityConfigurer.java
@@ -75,6 +75,7 @@
            List<String> securityIgnoreUrls = systemConfig.getSecurityIgnoreUrls();
            String[] ignores = new String[securityIgnoreUrls.size()];
            http
                    .addFilterAt(authenticationFilter(), UsernamePasswordAuthenticationFilter.class)
                    .exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint)
                    .and().authenticationProvider(restAuthenticationProvider)
                    .authorizeRequests()
@@ -99,26 +100,25 @@
                    .and().rememberMe().key(CookieConfig.getName()).tokenValiditySeconds(CookieConfig.getInterval()).userDetailsService(formDetailsService)
                    .and().csrf().disable()
                    .cors();
            http.addFilterAt(authenticationFilter(), UsernamePasswordAuthenticationFilter.class);
        }
//        /**
//         * Cors configuration source cors configuration source.
//         *
//         * @return the cors configuration source
//         */
//        @Bean
//        public CorsConfigurationSource corsConfigurationSource() {
//            final CorsConfiguration configuration = new CorsConfiguration();
//            configuration.setMaxAge(3600L);
//            configuration.setAllowedOrigins(Collections.singletonList("*"));
//            configuration.setAllowedMethods(Collections.singletonList("*"));
//            configuration.setAllowCredentials(true);
//            configuration.setAllowedHeaders(Collections.singletonList("*"));
//            final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//            source.registerCorsConfiguration("/api/**", configuration);
//            return source;
//        }
        /**
         * Cors configuration source cors configuration source.
         *
         * @return the cors configuration source
         */
        @Bean
        public CorsConfigurationSource corsConfigurationSource() {
            final CorsConfiguration configuration = new CorsConfiguration();
            configuration.setMaxAge(3600L);
            configuration.setAllowedOrigins(Collections.singletonList("*"));
            configuration.setAllowedMethods(Collections.singletonList("*"));
            configuration.setAllowCredentials(true);
            configuration.setAllowedHeaders(Collections.singletonList("*"));
            final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/api/**", configuration);
            return source;
        }
        /**