本文項目參考自:https://github.com/boylegu/SpringBoot-vuejavascript
這個項目主要講的是一些概念,想要本身實現代碼操做請看:http://www.javashuo.com/article/p-xmeowceo-gu.htmlcss
爲了完成此項目你須要會springBoot,mybatis的一些基本操做html
運行界面前端
①安裝node.js,下載相應版本的node.js,下載地址:https://nodejs.org/en/download/,下載完雙擊安裝,點擊下一步直到安裝完成
②安裝完成後,附件裏選擇命令提示符(或者在開始的搜索框裏輸入cmd回車調出命令面板)輸入:node -v回車,出現相應版本證實安裝成功,
node環境已經安裝完成,因爲有些npm有些資源被屏蔽或者是國外資源的緣由,常常會致使用npm安裝依賴包的時候失敗,全部我還須要npm的
國內鏡像---cnpm。在命令行中輸入:npm install -g cnpm –registry=https://registry.npm.taobao.org回車,大約須要3分鐘,
若是報錯或沒反應,則卸掉node.js從新安裝
③安裝全局vue-cli腳手架,用於幫助搭建所需的模板框架。輸入命令:cnpm install -g vue-cli回車等待完成。
④建立項目,首先咱們要選定目錄,而後再命令行中把目錄轉到選定的目錄,假如咱們打算把項目新建在e盤下的vue文件夾中則輸入下面的命令:
e:回車,而後cd vue,而後輸入命令:vue init webpack 項目文件夾名稱,回車,運行初始化命令的時候會讓用戶輸入幾個基本的選項,
如項目名稱,描述,做者等信息,若是不想填直接回車默認就好。(一頓回車+N鍵就完成了)
⑤安裝項目所需的依賴包,首先輸入:cd 項目名回車,而後輸入:cnpm install回車等待安裝,安裝完成以後,會在咱們的項目目錄firstVue
文件夾中多出一個node_modules文件夾,這裏邊就是咱們項目須要的依賴包資源。安裝完依賴包以後,就能夠運行整個項目了。
⑥測試環境是否搭建成功,在cmd裏輸入:cnpm run dev回車,項目運行成功後,瀏覽器會自動打開localhost:8080(若是瀏覽器沒有自動打開
,能夠手動輸入)。運行成功後,會看到Welcome to Your Vue.js App頁面。
CREATE TABLE persons
(id integer,
create_datetime datetime,
email varchar(255),
phone varchar(255),
sex varchar(255),
username varchar(255),
zone blob,
primary key (id));
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'gubaoer@hotmail.com', 08613000001111, 'male', 'gubaoer', 'HongKou District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'boyle.gu@hotmail.com', 08613000001112, 'male', 'baoer.gu', 'JingAn District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'yoyo.wu@gmail.com', 08613000001113, 'female', 'yoyo.wu', 'JingAn District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'stacy.gao@126.com', 08613000001114, 'female', 'stacy.gao', 'MinHang District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'yomiko.zhu@qq.com', 08613000001115, 'female', 'yomiko.zhu', 'PuDong District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'hong.zhu@163.com', 08613000001116, 'male', 'hong.zhu', 'YangPu District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'leon.lai@qq.com', 08613000001117, 'male', 'leon.lai', 'JinShan District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'mark.lei@sohu.com', 08613000001118, 'male', 'mark.lei', 'HuangPu District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'wen.liu@360.com', 08613000001119, 'male', 'wen.liu', 'ChongMing District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'cai.lu@baidu.com', 08613000001120, 'female', 'cai.lu', 'BaoShan District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'alex.li@icee.com', 08613000001121, 'male', 'alex.li', 'ChangNing District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'sofia.xu@qq.com', 08613000001122, 'female', 'sofia.xu', 'ZhaBei District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'cora.zhang@qq.com', 08613000001123, 'female', 'cora.zhang', 'XuHui District');
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (now(), 'tom.gao@hotmail.com', 08613000001124, 'female', 'tom.gao', 'HuangPu District');
Vue (讀音 /vjuː/,相似於 view) 是一套用於構建用戶界面的漸進式框架與其它大型框架不一樣的是,Vue 被設計爲能夠自底向上逐層應用。Vue 的核心庫只關注視圖層,不只易於上手,還便於與第三方庫或既有項目整合。另外一方面,當與現代化的工具鏈以及各類支持類庫結合使用時,Vue 也徹底可以爲複雜的單頁應用提供驅動vue
components包下的內容java
<template> <div class="wrapper"> <db-header></db-header> <el-row class="container"> <el-col :span="4" class="menu"> <db-sidebar></db-sidebar> </el-col> <el-col :span="20" class="content"> <db-filterinput></db-filterinput> <db-table></db-table> </el-col> </el-row> <el-row> <el-col :span="24"> <footer class="footer"> <db-footer></db-footer> </footer> </el-col> </el-row> </div> </template> <script>
/*此處命名必須按照駝峯命名法,而且引入也須要遵照規則*/ import DbHeader from './components/DbHeader.vue' import DbSidebar from './components/DbSidebar.vue' import DbFilterinput from './components/DbFilterinput.vue' import DbTable from './components/DbTable.vue' import DbFooter from './components/DbFooter.vue' import ElRow from "element-ui/packages/row/src/row"; export default { name: 'app', components: { ElRow, DbHeader, DbSidebar, DbFilterinput, DbTable, DbFooter }, } </script> <style> element.style { background-color: rgb(10, 47, 88); } body { font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微軟雅黑", Arial, sans-serif; margin: 0; display: flex; min-height: 100vh; flex-direction: column; } .el-menu, body, html { height: 100%; } .wrapper { position: relative; } footer, div { display: block; } .container { padding-top: 70px; flex: 1; } .container, .wrapper { height: 100%; } .menu { height: 100%; background-color: #eef1f6; } .content { padding-top: 25px; padding-right: 25px; padding-bottom: 125px; padding-left: 25px; } .footer { height: 120px; background-color: #324057; color: #a4aebd; width: 100%; z-index: 1000; margin-top: -120px; line-height: 1; font-size: 22px; } </style>
vue文件中3大標籤的做用:node
/** * Created by wlovet on 18/1/17 */ import Vue from 'vue' import{ Button, Select, Row, Col, Pagination, Table, TableColumn, Form, FormItem, Input, Dialog, Option }from 'element-ui' //導入App.vue頁面入口組件 import App from './App.vue' //Element-UI使用指南 Element-UI是餓了麼前端團隊 //推出的一款基於Vue.js 2.0 的桌面端UI框架, //手機端有對應框架是 Mint UI import 'element-ui/lib/theme-default/index.css' import lang from 'element-ui/lib/locale/lang/en' import locale from 'element-ui/lib/locale' // 導入更多的第三方庫的組件 //Moment.js 是一個 JavaScript 日期處理類庫 //,用於解析、檢驗、操做、以及顯示日期 import moment from 'moment' //Vue2.0的網絡請求庫 import axios from 'axios' //curvejs 中文讀["克js"],是騰訊AlloyTeam //打造的一款魔幻線條框架, //讓線條成爲一名優秀的舞者, //讓線條們成爲優秀的舞團,HTML5 Canvas就是舞臺。 import curvejs from 'curvejs' //Object.defineProperty 是vue中雙向綁定的基礎。 //vue是經過數據劫持的方式來作數據綁定的, //最核心的方法是經過 Object.defineProperty() //方法來實現對屬性的劫持,達到能監聽到數據的變更。 Object.defineProperty(Vue.prototype, '$moment', { value: moment }); Object.defineProperty(Vue.prototype, '$axios', { value: axios }); Object.defineProperty(Vue.prototype, '$curvejs', { value: curvejs }); //引入Element-UI組件的步驟 Vue.use(Button); Vue.use(Select); Vue.use(Row); Vue.use(Col); Vue.use(Pagination); Vue.use(Table); Vue.use(TableColumn); Vue.use(Form); Vue.use(FormItem); Vue.use(Input); Vue.use(Dialog); Vue.use(Option); new Vue({ el:'#app', render:h=>h(App) })
//做爲vue組件之間信息交流的通道 import Vue from 'vue' const Bus = new Vue(); export default Bus
各個組件的內容具體信息可去github下載:https://github.com/boylegu/SpringBoot-vuemysql
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sunyard</groupId> <artifactId>SpringBoot-MVVM-Vue</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
spring.application.name=springboot-mvvm-vue server.port=8088 spring.datasource.url=jdbc:mysql://localhost:3306/springboot-mvvm-vue2 spring.datasource.username=root spring.datasource.password=123 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#掃描項目中的pojo類 mybatis.typeAliasesPackage=com.mycom.pojo
#掃描mapper包下的xml文件 mybatis.mapperLocations=classpath\:com/mycom/mapper/*.xml
package com.mycom; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Configuration; @SpringBootApplication //掃描dao包下的dao接口 @MapperScan("com.mycom.dao") //掃描config包下的CORSConfig類,用來解決axios的跨域請求問題 @Configuration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
這裏認爲你能夠得到persons表中全部數據webpack
package com.mycom.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import static org.springframework.web.cors.CorsConfiguration.ALL; /** * CORS configuration */ @Configuration public class CORSConfig { @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins(ALL) .allowedMethods(ALL) .allowedHeaders(ALL) .allowCredentials(true); } }; } }
不建這個類的話在前端部分使用axios(一種ajax的封裝)請求數據是會失敗!ios
介紹一下webpack是什麼?
•可以實現多種不一樣的前端模塊系統
•webpack 打包前端資源(模塊)時可以實現代碼分割,按需加載