国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

瀏覽:37日期:2022-09-30 14:58:15
一,前端VUE項目

這里使用VUE UI創(chuàng)建一個VUE項目

命令行輸入vue ui進入

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

手動配置項目

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

選中這三個

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

點擊下一步->點擊創(chuàng)建項目

用IDEA打開剛才創(chuàng)建的項目

IDEA中的安裝vue插件并重啟

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

IDEA控制臺中輸入vue add axios安裝axios

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

新建一個Show.vue

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

在index,js的routes中配置它的路由

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

編寫Show,vue向后端請求數(shù)據(jù)并展示

<template> <div><table> <tr><td>ID</td><td>姓名</td><td>性別</td> </tr> <tr v-for='user in users'><td>{{user.id}}</td><td>{{user.name}}</td><td>{{user.sex}}</td> </tr></table> </div></template><script> export default {name: 'Show',data(){ return{users:[ {id:'',name:'',sex:'', }] }},created() { const _this=this axios.get(’http://localhost:8888/user/showAll’).then(function (resp) {_this.users=resp.data })} }</script><style scoped></style>二,后端SpringBoot項目

編寫一個查詢功能

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

controller層返回json數(shù)據(jù)

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

在spring boot中解決跨域問題

重寫WebMvcConfigurer中的addCorsMappings()方法

@Configurationpublic class CrosConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) {registry.addMapping('/**').allowedOriginPatterns('*').allowedMethods('POST', 'GET', 'PUT', 'OPTIONS', 'DELETE').allowCredentials(true).maxAge(3600).allowedHeaders('*'); }}

后端測試(注意前后端端口號的區(qū)分,VUE占用了8080和8081,在Springboot中修改后端的端口號)

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

數(shù)據(jù)輸出成功

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

前端發(fā)請求拿數(shù)據(jù)

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

前端拿數(shù)據(jù)成功!!!

SpringBoot+VUE實現(xiàn)前后端分離的實戰(zhàn)記錄

總結(jié)

到此這篇關(guān)于SpringBoot+VUE實現(xiàn)前后端分離的文章就介紹到這了,更多相關(guān)SpringBoot+VUE前后端分離內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 乐陵市| 安达市| 尤溪县| 阳城县| 利辛县| 武义县| 定陶县| 福清市| 米脂县| 德兴市| 唐河县| 五家渠市| 罗定市| 白玉县| 江门市| 京山县| 靖州| 光山县| 丽水市| 崇礼县| 西充县| 色达县| 疏附县| 太仓市| 青海省| 庆安县| 阿城市| 松滋市| 沾化县| 黔江区| 南宫市| 新郑市| 修水县| 噶尔县| 灯塔市| 济源市| 金溪县| 武鸣县| 博客| 安庆市| 巴彦淖尔市|