利用SpringBoot和Vue实现前后端分离(附源码)(1)

private StudentService studentService;

@CrossOrigin //标识接受跨域处理

@RequestMapping(value=“/studentList” ,method= RequestMethod.GET)

public ActionResult findAllStu(){

ActionResult actionResult = new ActionResult();

List allService = studentService.findAllService();

actionResult.setStatusCode(200);

actionResult.setData(allService);

return actionResult;

}

//修改学生信息

@CrossOrigin

@RequestMapping(value = “/updateStudent”,method = RequestMethod.PUT)

public ActionResult updateStu(@RequestBody Student student){

studentService.updateStudentService(student);

ActionResult actionResult = new ActionResult();

actionResult.setStatusCode(200);

actionResult.setMsg(“Update Success!!!”);

return actionResult;

}

//添加学生信息

@CrossOrigin

@RequestMapping(value=“/addStudent” ,method= RequestMethod.POST)

public ActionResult addStu(@RequestBody Student student){

Student student1 = studentService.addStudentService(student);

ActionResult result = new ActionResult();

result.setStatusCode(200);

result.setMsg(“add Success!!!”);

result.setData(student1);

return result;

}

//删除学生信息

@CrossOrigin

@RequestMapping(value = “/deleteStudent”,method = RequestMethod.GET)

public ActionResult deleteStu(@RequestParam(“id”) int id){

studentService.deleteStudentService(id);

ActionResult actionResult = new ActionResult();

actionResult.setStatusCode(200);

actionResult.setMsg(“Update Success!!!”);

return actionResult;

}

}

4. 前台实现

===========================================================================

环境搭建:

Vue基础:https://blog.csdn.net/weixin_42601136/article/details/108297010

添加axios

cnpm install axios --save

在这里插入图片描述

4.1 main.js


引用ElementUI的组件,引用axios并设置基础的url

// The Vue build version to load with the import command

// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from ‘vue’

import App from ‘./App’

import router from ‘./router’

import ElementUI from ‘element-ui’

import ‘element-ui/lib/theme-chalk/index.css’

//引用axios,设置基础的url

var axios = require(‘axios’)

axios.defaults.baseURL = ‘http://localhost:8088/api’

//绑定到全局

Vue.prototype.$axios = axios

Vue.config.productionTip = false

Vue.use(ElementUI)

Vue.config.productionTip = false

/* eslint-disable no-new */

new Vue({

el: ‘#app’,

router,

components: { App },

template: ‘’

})

4.2 index.js


添加路由

import Vue from ‘vue’

import Router from ‘vue-router’

import IndexView from ‘@/view/index’

import MainView from ‘@/view/admin/main’

import LoginView from ‘@/view/login’

import WelcomeView from ‘@/view/admin/welcome’

import StudentView from ‘@/view/admin/student’

Vue.use(Router)

export default new Router({

routes: [

{//前台首页

path: ‘/’,

name: ‘IndexView’,

component: IndexView

},

{//后台主页面

path:“/main”,

component:MainView,

children:[

{path:“/”,component:WelcomeView},

{path:“/showStudent”,component:StudentView}

]

},

{//登录页

path:“/login”,

component:LoginView,

}

]

})

4.3 index.vue


访问的默认页面

搜索

登录

学生管理系统

©kak.com 京ICP证XXXXX号,本网站所列数据,除特殊说明,所有数据均出自我司实验室测试

在这里插入图片描述

4.4 login.vue


点击登录触发的页面

登录页面

<el-button type=“primary” @click=“submitForm(‘ruleForm2’)”>提交

<el-button @click=“resetForm(‘ruleForm2’)”>重置

回到首页

在这里插入图片描述

4.5 main.vue


登录成功后的页面,与欢迎页面一起展示

导航一

学生信息

选项2

选项3

选项4

选项4-1

导航二

选项1

选项2

选项3

选项4

选项4-1

导航三

选项1

选项2

选项3

选项4

选项4-1

查看

新增

删除

kak

4.6 welcome.vue


欢迎页面,加载主页面时默认的页面

在这里插入图片描述

4.7 student.vue


与后台进行跨域访问,实现增删改查

<el-button size=“mini” @click=“handleEdit(scope.$index, scope.row)”>修改

<el-button size=“mini” type=“danger” @click=“handleDelete(scope.$index, scope.row)”>删除

<el-button @click=“dialogFormVisible = false”>取 消

<el-button type=“primary” @click=“updateStudent()”>确 定

<el-button type=“primary” @click=“addView()”>添加学生信息

<el-button @click=“dialogFormVisible1 = false”>取 消

<el-button type=“primary” @click=“addStudent()”>确 定

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值