Vue整合SpringBoot项目实战之后端业务处理

Vue+SpringBoot后台业务

Springboot实现CRUD,前后端分离

技术栈

  • SpringBoot
  • JPA

源码

前端项目代码

后端项目代码

重点:跨域请求,可参见见Vue整合SpringBoot项目实战之解决前后端分离的跨域问题这篇博客

package com.vuespringboot.demo.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;

/**
 * @author Cody
 * @date 2020/7/17 - 14:08
 */
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    private CorsConfiguration corsConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        /*
         *请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等)
         */
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.setMaxAge(3600L);
        return corsConfiguration;
    }

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", corsConfig());
        return new CorsFilter(source);
    }
}

注意事项:

  • 修改配置数据库的信息

  • 需要用到IDEA中的Lombok插件(省略Get、Set方法)

猜你喜欢

转载自blog.csdn.net/qq_45077173/article/details/107546914