前后端分离项目实战(Vue+SSM)

简介: 前后端分离项目实战(Vue+SSM)

技术介绍

前端:Vue.js、ElementUI、Axios、Vue-Router

后端:SSM(Spring+SpringMVC+MyBatis)

数据库:MySql

运行界面

后端

登录界面

image.png

首页以及其他页面(部分展示)

image.png

image.png

前端

首页

image.png

详情页

image.png

登录

image.png核心代码

这边只展示核心代码(跨域问题),普通的SSM框架项目,没有使用maven工程,源码已放在Github上,地址在文章末。

后端配置跨域

新建一个CorsFilter.java文件

import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CorsFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        response.addHeader("Access-Control-Allow-Origin", "*");                                      //允许所有网址发来的请求
        response.addHeader("Access-Control-Allow-Methods", "REQUEST,GET,POST,PUT,DELETE,PATCH,HEAD");//允许的请求方法
        response.addHeader("Access-Control-Allow-Headers", "Content-Type");                          //,X-Requested-With,auth_token
        response.addHeader("Access-Control-Max-Age", "1800");//30 min
        filterChain.doFilter(request, response);
    }
}

在web.xml中进行配置,注意文件路径位置要正确。注意在调用接口时,加上注解@ResponseBody

   <filter>
        <filter-name>cors</filter-name>
        <filter-class>cn.smbms.interceptor.CorsFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>cors</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

前端配置

在config/index.js中

image.png

 

        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {
            '/api': {
                target: '', // 后端地址
                changeOrigin: true, //是否跨域
                https: true,
                pathRewrite: {
                    '^/api': '' //需要rewrite的,
                }
            }
        },

项目源码地址:https://github.com/dragon-lee-add/JavaEE-Vue


相关文章
|
4天前
|
JavaScript
VUE里的find与filter使用与区别
VUE里的find与filter使用与区别
14 0
|
4天前
|
JavaScript
vue页面加载时同时请求两个接口
vue页面加载时同时请求两个接口
|
4天前
|
JavaScript
vue里样式不起作用的方法,可以通过deep穿透的方式
vue里样式不起作用的方法,可以通过deep穿透的方式
13 0
|
4天前
|
移动开发 JavaScript 应用服务中间件
vue打包部署问题
Vue项目`vue.config.js`中,`publicPath`设定为&quot;/h5/party/pc/&quot;,在线环境基于打包后的`dist`目录,而非Linux的`/root`。Nginx代理配置位于`/usr/local/nginx/nginx-1.13.7/conf`,包含两个相关配置图。
vue打包部署问题
|
4天前
|
JavaScript 前端开发
iconfont 图标在vue里的使用
iconfont 图标在vue里的使用
15 0
|
5天前
|
存储 JavaScript
Vue当前时间与接口返回时间的判断
Vue当前时间与接口返回时间的判断
14 0
|
5天前
|
JavaScript 前端开发
Vue生成Canvas二维码
Vue生成Canvas二维码
9 0
|
5天前
|
JavaScript 前端开发 开发者
new Vue() 发生了什么
new Vue() 发生了什么
10 1
|
1天前
|
JavaScript
vue知识点
vue知识点
7 1
|
3天前
|
JavaScript
vue打印v-model 的值
vue打印v-model 的值