springboot 整合vue就行前后端完全分离,监听器,过滤器,拦截器 https://github.com/ninuxGithub/spring-boot-vue-separate
A blog built up with Spring Boot in the back end and Vue.js in the front-end  https://github.com/arocketman/SpringBlog  (thymeleaf vue ,没有前后端分离)

overview

Now about Web develop fields. It's very bloated, outmoded and some development efficiency have a lower with each other than other dynamic language when people refers to Java. Even before somebody shouts loudly ‘Java was died’. But is this really the case? In fact, If you often attention to Java in long time, your feel is too deep. Though it's many disadvantages and verbose. It couldn't be denied that Java is still best language in industry member, and advance with the times. This project is a CRUD demo example base Spring Boot with Vue2 + webpack2. I hope pass thought this project for express Java microservice fast full stack base web practice.

Why Spring Boot

Spring is a very popular Java-based framework for building web and enterprise applications. Unlike many other frameworks, which focus on only one area, Spring framework provides a wide verity of features addressing the modern business needs via its portfolio projects.

In relation to Spring, Spring Boot aims to make it easy to create Spring-powered, production-grade applications and services with minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need.

The diagram below shows Spring Boot as a point of focus on the larger Spring ecosystem:

The primary goals of Spring Boot are:

  • To provide a radically faster and widely accessible ‘getting started’ experience for all Spring development.

  • To be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults.

  • To provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration).

Spring Boot does not generate code and there is absolutely no requirement for XML configuration.

Below are this project code snippet. Do you think simple?

  1. @RestController
  2. @RequestMapping("/api/persons")
  3. public class MainController {
  4.  
  5. @RequestMapping(
  6. value = "/detail/{id}",
  7. method = RequestMethod.GET,
  8. produces = MediaType.APPLICATION_JSON_VALUE
  9. )
  10. public ResponseEntity<Persons> getUserDetail(@PathVariable Long id) {
  11.  
  12. /*
  13. * @api {GET} /api/persons/detail/:id details info
  14. * @apiName GetPersonDetails
  15. * @apiGroup Info Manage
  16. * @apiVersion 1.0.0
  17. *
  18. * @apiExample {httpie} Example usage:
  19. *
  20. * http GET http://127.0.0.1:8000/api/persons/detail/1
  21. *
  22. * @apiSuccess {String} email
  23. * @apiSuccess {String} id
  24. * @apiSuccess {String} phone
  25. * @apiSuccess {String} sex
  26. * @apiSuccess {String} username
  27. * @apiSuccess {String} zone
  28. */
  29.  
  30. Persons user = personsRepository.findById(id);
  31.  
  32. return new ResponseEntity<>(user, HttpStatus.OK);
  33. }
  34.  
  35. }

Why MVVM

Although it seems similar to MVC (except with a "view model" object in place of the controller), there's one major difference — the view owns the view model. Unlike a controller, a view model has no knowledge of the specific view that's using it.

This seemingly minor change offers huge benefits:

  1. View models are testable. Since they don't need a view to do their work, presentation behavior can be tested without any UI automation or stubbing.

  2. View models can be used like models. If desired, view models can be copied or serialized just like a domain model. This can be used to quickly implement UI restoration and similar behaviors.

  3. View models are (mostly) platform-agnostic. Since the actual UI code lives in the view, well-designed view models can be used on the iPhone, iPad, and Mac, with only minor tweaking for each platform.

  4. Views and view controllers are simpler. Once the important logic is moved elsewhere, views and VCs become dumb UI objects. This makes them easier to understand and redesign. In short, replacing MVC with MVVM can lead to more versatile and rigorous UI code.

In short, replacing MVC with MVVM can lead to more versatile and rigorous UI code.

Why to choose Vue.js

Vue.js is relatively new and is gaining lot of traction among the community of developers. VueJs works with MVVM design paradigm and has a very simple API. Vue is inspired by AngularJS, ReactiveJs and updates model and view via two way data binding.

Components are one of the most powerful features of Vue. They help you extend basic HTML elements to encapsulate reusable code. At a high level, components are custom elements that Vue’s compiler attaches behavior to.

What's Webpack

Webpack is a powerful tool that bundles your app source code efficiently and loads that code from a server into a browser. It‘s excellent solution in frontend automation project.

Demo

This's a sample ShangHai people information system as example demo.

Feature (v0.1)

  • Spring Boot (Back-end)

    • Build RestFul-API on SpringBoot with @RequestMapping and base CRUD logic implementation

    • Handle CORS(Cross-origin resource sharing)

    • Unit test on SpringBoot

    • Support hot reload

    • Add interface documents about it's rest-api

    • Pagination implementation of RestFul-API with JPA and SpringBoot

  • VueJS & webpack (front-end)

    • Follow ECMAScript 6

    • What about coding by single file components in vueJS

    • Simple none parent-child communication and parent-child communication

    • Interworking is between data and back-end

    • How grace import third JS package in vue

    • Handle format datetime

    • Pagination implementation

    • Reusable components

      • DbHeader.vue
      • DbFooter.vue (sticky footer)
      • DbFilterinput.vue
      • DbModal.vue
      • DbSidebar.vue
      • DbTable.vue
    • Config front-end env on webpack2 (include in vue2, handle static file, build different environment...... with webpack2)

Main technology stack

  • Java 1.7
  • Spring Boot 1.5.x
  • Maven
  • sqlite (not recommend, only convenience example)
  • vueJS 2.x
  • webpack 2.x
  • element ui
  • axios

Preparation

  • Please must install Java 1.7 or even higher version

  • install Node.js / NPM

  • Clone Repository

    1. git clone https://github.com/boylegu/SpringBoot-vue.git
    2. cd springboot_vue

Installation

  • Build front-end environment

    1. cd springboot_vue/frontend
    2. npm install

Usage

  • Run back-end server

    1. cd springboot_vue/target/
    2. java -jar springboot_vue-0.0.1-SNAPSHOT.jar

  • Run Front-end Web Page

    1. cd springboot_vue/frontend
    2. npm run dev

You can also run cd springboot_vue/frontend;npm run build and it's with Nginx in the production environment

Future Plan

This project can be reference,study or teaching demonstration. After, I will update at every increme version in succession. In future,I have already some plan to below:

  1. User Authentication
  2. state manage with vuex
  3. use vue-route
  4. add docker deploy method
  5. support yarn ... ...

Support

  1. Github Issue

  2. To e-mail: gubaoer@hotmail.com

  3. You can also join to QQ Group: 315308272

Related projects

SpringBoot + 前端MVVM 基于Java的微服务全栈快速开发实践

Convenient & efficient and better performance for Java microservice full stack.

Commemorate the 6 anniversary of enter the profession.

Give beginner as a present.

———————By Boyle Gu

背景

如今Web开发领域,当有人提到Java时,总会让人觉得臃肿、古老而过时且开发效率没有某些动态语言高效,甚至在此之前还有人高喊“Java 已死!”,但是事实真是如此吗?其实如果你一直关注着Java,那你的感悟会更深,尽管它有很多的缺点和啰嗦,但不可否认,Java依然是工业界中最优秀的语言,而且它一直保持着与时俱进。本项目将使用SpringBoot + Vue2 + Webpack2 配合最简单CRUD的逻辑来展示一个基于Java的微服务全栈快速开发实践的Demo。

在某些时候,其开发效率已经并不比某些动态语言低。

为什么是SpringBoot

首先先来简单的介绍一下Spring,它是目前Java生态中最广为人知、流行的企业级Web框架。不像其他一些框架仅聚焦在某个领域,Spring框架通过其容器化组件式管理及开发,可提供或定制各式各样的功能来满足企业化需求。

那么相较于Spring,Spring Boot的目标是更加容易的创建Spring应用、建立自动化、最少人为干预的生产级配置,真正意义做到开箱即用,并且对于新用户及Spring平台的用户极易上手,快速开发。

下图主要展示了Spring Boot在Spring庞大的生态圈中的层级关系

SpringBoot的目标主要:

  • 为所有Spring开发提供一个从根本上更快,且随处可得的入门体验。

  • 开箱即用,但通过不采用默认设置可以快速摆脱这种方式。

  • 提供一系列大型项目常用的非功能性特征,比如:内嵌服务器,安全,指标,健康检测,外部化配置。

绝对没有代码生成,也不需要XML配置。

下面展示的是本项目的SpringBoot相关代码片段,你觉得简单么?

  1. @RestController
  2. @RequestMapping("/api/persons")
  3. public class MainController {
  4.  
  5. @RequestMapping(
  6. value = "/detail/{id}",
  7. method = RequestMethod.GET,
  8. produces = MediaType.APPLICATION_JSON_VALUE
  9. )
  10. public ResponseEntity<Persons> getUserDetail(@PathVariable Long id) {
  11.  
  12. /*
  13. * @api {GET} /api/persons/detail/:id details info
  14. * @apiName GetPersonDetails
  15. * @apiGroup Info Manage
  16. * @apiVersion 1.0.0
  17. *
  18. * @apiExample {httpie} Example usage:
  19. *
  20. * http GET http://127.0.0.1:8000/api/persons/detail/1
  21. *
  22. * @apiSuccess {String} email
  23. * @apiSuccess {String} id
  24. * @apiSuccess {String} phone
  25. * @apiSuccess {String} sex
  26. * @apiSuccess {String} username
  27. * @apiSuccess {String} zone
  28. */
  29.  
  30. Persons user = personsRepository.findById(id);
  31.  
  32. return new ResponseEntity<>(user, HttpStatus.OK);
  33. }
  34.  
  35. }

为什么是MVVM

那么在我继续之前,我也想和大家回顾一下Web开发的发展简史:

  • 第一阶段: 网页三剑客,生猛的通过原生javascript直接操作Dom树;

  • 第二阶段: JQuery诞生,配合前端MVC为代表的Backbone.js, 让我们可以优雅而简单的操作Dom树;

  • 第三阶段: 后端架构升级为MVC,前后端分工更清晰,前端工程化、ECMAScript规范开始崭露头角;

  • 第四阶段: 后端架构进入了微服务时代,前端架构不仅升级为MVVM,ES6更是成为目前事实上的标准;

在这里,我不想过于神化MVVM有多么的先进,JQuery为代表的MVC有多么的落后,但确实MVVM有着很多先进的特性:

  • 低开销

  • 易维护

  • 可重用

为什么选择Vue.js

Vue.js是MVVM设计模式中目前最火热的一个前端框架之一,除了性能表现优异之外,与类似React相比,更轻量级、更容易上手。

通过Vue中的“单文件组件”特性,更灵活的定义组件,不仅使代码结构更清晰,而且能与任何其他组件进行随意组合,更具复用性。

Webpack是什么

Webpack提供了一整套前端工程自动化的解决方案

Demo

一个简单的“上海人员信息查询系统”作为例子

具备的功能(v0.1)

  • Spring Boot (后端)

    • 通过在Spring Boot中建立基于RestFul-API并使用@ RequestMapping实现一个基本的CRUD逻辑

    • 处理CORS(跨域资源共享)

    • 在Spring Boot中进行单元测试

    • 支持热加载

    • 增加api接口文档

    • 通过SpringBoot配合JPA来实现RestFul-API的分页

  • VueJS & webpack (前端)

    • 遵循ECMAScript 6 规范

    • 如何在vue中使用‘单文件组件’进行开发编码

    • 演示‘非父子组件’如何进行简单的通信以及‘父子组件’之间如何传递数据

    • 如何和后端进行数据交互

    • 如何在vue中优雅的引入第三方JS库

    • 格式化时间

    • 分页实现

    • 可复用组件

      • DbHeader.vue
      • DbFooter.vue (sticky footer)
      • DbFilterinput.vue
      • DbModal.vue
      • DbSidebar.vue
      • DbTable.vue

      得益于类似vue、react等MVVM模式,本项目的任何组件,只要您觉得合适,都可以复用在您的任何项目中,避免重复造轮子。

    • 如何通过webpack2配置来自动化构建前端环境(包括如何配置vue2、处理静态文件,构建不同环境等等)

本项目主要技术栈

  • Java 1.7
  • Spring Boot 1.5.x
  • Maven
  • sqlite (not recommend, only convenience example)
  • vueJS 2.x
  • webpack 2.x
  • element ui
  • axios

准备工作

  • 安装JDK1.7或更新的版本

  • 安装Node.js/NPM

  • 克隆仓库

    1. git clone https://github.com/boylegu/SpringBoot-vue.git
    2. cd springboot_vue

安装

  • 编译前端开发环境

    1. cd springboot_vue/frontend
    2. npm install

使用

  • 运行Spring Boot后端服务

    1. cd springboot_vue/target/
    2. java -jar springboot_vue-0.0.1-SNAPSHOT.jar

  • 运行前端服务

    1. cd springboot_vue/frontend
    2. npm run dev

你也可以在生产环境中运行cd springboot_vue/frontend;npm run build进行编译并配合Nginx

未来计划

本项目可以作为工作参考、学习或者教学演示,之后将陆续以版本的形式,即每个版本都会新增不同的功能演示项,不定期进行发布更新,有以下功能已经在计划之中:

  1. 用户认证
  2. 引入更高级的vuex组件通信机制
  3. 演示vue-route的使用
  4. 加入docker部署环境
  5. 新增针对yarn的支持 ... ...

技术、教学支持

由于个人时间暂时有限,关于Spring、Vue、webpack等所有的核心的议题内容非常庞大,因此我将以以下形式来回答和解释关于本项目Demo问题:

  1. 以Github Issue的形式进行提问
  2. 电子邮件的形式 gubaoer@hotmail.com
  3. QQ群:315308272

相关项目

https://github.com/boylegu/SpringBoot-vue/blob/master/README-CN.md

SpringBoot vue的更多相关文章

  1. springboot+vue前后端分离,nginx代理配置 tomcat 部署war包详细配置

    1.做一个小系统,使用了springboot+vue 基础框架参考这哥们的,直接拿过来用,链接https://github.com/smallsnail-wh/interest 前期的开发环境搭建就不 ...

  2. SpringBoot+Vue+WebSocket 实现在线聊天

    一.前言 本文将基于 SpringBoot + Vue + WebSocket 实现一个简单的在线聊天功能 页面如下: 在线体验地址:http://www.zhengqingya.com:8101 二 ...

  3. Springboot vue.js html 跨域 前后分离 shiro权限 集成代码生成器

    本代码为 Springboot vue.js  前后分离 + 跨域 版本 (权限控制到菜单和按钮) 后台框架:springboot2.1.2+ mybaits+maven+接口 前端页面:html + ...

  4. .gitignore 标准模板 -适用于SpringBoot+Vue项目 -Idea+VSCode开发

    .gitignore 标准模板 -适用于SpringBoot+Vue项目 node_modules/ target/ !.mvn/wrapper/maven-wrapper.jar ### STS # ...

  5. SpringBoot+Vue前后端分离,使用SpringSecurity完美处理权限问题

    原文链接:https://segmentfault.com/a/1190000012879279 当前后端分离时,权限问题的处理也和我们传统的处理方式有一点差异.笔者前几天刚好在负责一个项目的权限管理 ...

  6. SpringBoot + Vue + nginx项目部署(零基础带你部署)

    一.环境.工具 jdk1.8 maven spring-boot idea VSVode vue 百度网盘(vue+springboot+nginx源码): 链接:https://pan.baidu. ...

  7. 使用Docker部署Spring-Boot+Vue博客系统

    在今年年初的时候,完成了自己的个Fame博客系统的实现,当时也做了一篇博文Spring-boot+Vue = Fame 写blog的一次小结作为记录和介绍.从完成实现到现在,也断断续续的根据实际的使用 ...

  8. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

  9. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作

    相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...

  10. Springboot+Vue实现仿百度搜索自动提示框匹配查询功能

    案例功能效果图 前端初始页面 输入搜索信息页面 点击查询结果页面 环境介绍 前端:vue 后端:springboot jdk:1.8及以上 数据库:mysql 核心代码介绍 TypeCtrler .j ...

随机推荐

  1. Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  2. OAF中的TableLayout 高级表格

    我们经常会遇到这种情况,我们要把显示界面分成几块区域来分别显示不同的内容.比如在同一行左边显示messageComponentLayout,右边显示table,这时,我们就要用到tableLayout ...

  3. how tomcat works 读书笔记 八 载入器下

    载入类 我们看看之前的文章,这一节就从SimpleWrapper的loadServlet讲起. SimpleWrapper.java如下(省略了try catch及其他部分代码) public Ser ...

  4. 网站开发进阶(十二)JS实现打印功能(包括打印预览、打印设置等)

    JS实现打印功能(包括打印预览.打印设置等) 绪 最近在进行项目开发时,需要实现后台管理端打印功能,遂在网上一阵搜索,搜到了很多相关的文章.其中绝大部分文章都是使用的Lodop5.0(Web打印和套打 ...

  5. 关于Maven中打包命令(项目中打补丁的时候用到)

     打jar包的方式  mvn package -Dmaven.test.skip=true              mvn install -Dmaven.test.skip=true      ...

  6. Shell Script - 追踪与debug

    [root@www ~]# sh [-nvx] scripts.sh 选项与参数: -n :不要运行 script,仅查询语法的问题: -v :再运行 sccript 前,先将 scripts 的内容 ...

  7. Hyper Text Transfer Protocol(超文本传输协议)

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  8. Ubuntu系统下配置IP地址方法介绍

    配置IP方式有两种: 1.通过命令直接配置 sudo ifconfig eth0 IP地址 netmask 子网掩码------配置IP地 sudo route add default gw 网关-- ...

  9. 163邮箱 SMTP发送邮件注意点

    在之前163邮箱注册的时候默认开通SMTP服务的,之后需要自己手动开始. 在配置的时候服务器的地址固定 用户名称就是你的邮箱 密码需要注意的是有的是你邮箱的密码,如果不对需要填写你的授权码!

  10. 如何将代码提交到git上

    http://blog.csdn.net/laozitianxia/article/details/50682100 这个博客介绍的很详细.