ps:目前这个项目只是有一个大致的框架,并没有做完

前期准备工作

前端构建工具:Visual Studio Code
后端构建工具:IDEA
数据库和服务器构建工具:WampServer (使用的是2.4.23版本对的apache,5.7.14版本的MySQL)
安装10.0以上版本的node

前端构建--采用vue+element-ui (vue使用的是3.0以上的版本)

1.使用指令vue create project 然后选择相关选项
2.构建项目目录
 2.1 vue3.0版本一下目录结构
  build 这个是我们最终发布的时候会把代码发布在这里,在开发阶段,我们基本不用管。
    | |-- build.js // 生产环境构建代码
    | |-- check-version.js // 检查node、npm等版本
    | |-- dev-client.js // 热重载相关
    | |-- dev-server.js // 构建本地服务器
    | |-- utils.js // 构建工具相关
    | |-- webpack.base.conf.js // webpack基础配置
    | |-- webpack.dev.conf.js // webpack开发环境配置
    | |-- webpack.prod.conf.js // webpack生产环境配置
  config 配置目录,默认配置没有问题,所以我们也不用管
    | |-- dev.env.js // 开发环境变量
    | |-- index.js // 项目一些配置变量
    | |-- prod.env.js // 生产环境变量
    | |-- test.env.js // 测试环境变量
  node_modules 这个目录是存放我们项目开发依赖的一些模块,这里面有很多很多内容,不过高兴的是,我们也不用管
  src 我们的开发目录,基本上绝大多数工作都是在这里开展的
  static 资源目录,我们可以把一些图片啊,字体啊,放在这里。
    | |-- assets // 资源目录
    | |-- components // vue公共组件
    | |-- store // vuex的状态管理
    | |-- App.vue // 页面入口文件
    | |-- main.js // 程序入口文件,加载各种公共组件
  test 初始测试目录,没用,删除即可
  .xxxx文件 这些是一些配置文件,包括语法配置,git配置等。基本不用管,放着就是了
  index.html 首页入口文件,基本不用管,如果是开发移动端项目,可以在head区域加上你合适的meta头
  package.json 项目配置文件。前期基本不用管,但是你可以找一下相关的资料,学习一下里面的各项配置。至少,要知道分别是干嘛的。初期就不管了。
  README.md 不用管
 2.2vue3.0项目结构
  noed_modules 这个目录是存放我们项目开发依赖的一些模块,这里面有很多很多内容,不过高兴的是,我们也不用管
  public 存放index.html和默认的icon
  src 开发目录
     assets 资源目录
     views 组件视图目录
     router 路由目录
     style 样式目录
     utils 公共组件目录
     以及一些其他根据项目添加的相关目录等
  packages.json 项目依赖文件,可以看到相关依赖等
  vue.config.js 项目配置文件,可以更改相关配置
3.进入项目目录,执行npm install安装相关依赖库
4.执行yarn serve或者npm install 来运行项目
5.配置一些相关的依赖:
  axios:
    安装axios:npm install --save axios
    将axios配置为全局:在main.js文件中引入axios依赖,并添加Vue.prototype.$axios = axios
  echatrs:
    安装echarts: npm install --save echarts
    将echarts配置为全局:在main.js文件中引入echarts依赖并添加Vue.prototype.$echarts = echart
  svg-sprite-loader:
    安装svg-sprite-loader:npm install --save svg-sprite-loader
    配置svg-sprite-loader:在vue.config.js文件中进行如下配置:

  1. chainWebpack: config => {
  2. // alias 配置
  3. config.resolve.alias;
  4. config.resolve.alias.set ('@', resolve ('src')); //设置@为src路径
  5. //配置svg
  6. config.module.rules.delete ('svg');
  7. config.module.rule ('svg').exclude.add (resolve ('src/icons')).end ();
  8. config.module
  9. .rule ('svg-smart')
  10. .test (/\.svg$/)
  11. .include.add (resolve ('src/icons/svg'))
  12. .end ()
  13. .use ('svg-sprite-loader')
  14. .loader ('svg-sprite-loader')
  15. .options ({
  16. symbolId: '[name]',
  17. });
  18. },
ps:使用chainWebpack,修改webpack相关配置,强烈建议先熟悉webpack-chain和vue-cli 源码,以便更好地理解这个选项的配置项

前端项目源码地址:https://github.com/wly13/admin-system

后端采用spring boot来搭建

1.在ide中创建一个JavaWeb项目:打开idea -> file -> new -> project ->spring initialzr -> next,填写maven相关工程配置 -> next,选择web -> next -> finsh。到此一个spring boot的后台项目就初始化成功
2.认识一个后台系统的目录开发结构:
  源码目录:src/main/java
    controller:前端控制器-主要是用于写前端调用的接口
    dao:数据操作层-主要是写各种数据操作方法的接口
    domain(bean):实体类-主要是写后端实体类(必须有无参构造函数,以及get和set)
    service:数据服务层-service层主要调用dao层的功能实现增删改查
    utils:工具类-主要用于存放项目的一些公共类
    config:配置信息类
    constant:常量接口类
    Application.java:工程启动类
  资源目录:src/main/resources
    i18n:国际化资源
    application.yml:项目配置文件-主要用于配置数据库访问,系统编码等各种配置
    static:静态资源目录-主要用于存放各种静态资源
    templates:模板目录-主要用于存放一些共用的模板
    mybatis.xml:mybatis配置文件
    mapper:mybatis映射文件-主要是用于写sql语句
  测试目录:src/main/test
  输出目录:target
  pom.xml:maven配置文件-在 pom.xml 中添加所需要的依赖信息,然后在项目根目录执行 mvn install 命令,maven就会自动下载相关依赖jar包到本地仓库
3.各个目录下的一些列子
controller/ListController.java:

  1. package com.example.vue.controller;
  2.  
  3. import com.example.vue.service.ListService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.*;
  6.  
  7. import java.util.List;
  8. import java.util.Map;
  9.  
  10. @RestController //控制器注解 表示所有数据都以json格式返回
  11. @CrossOrigin //跨域注解
  12. public class ListController {
  13. @Autowired //自动导入某个bean/domain
  14. private ListService listService;
  15.  
  16. @RequestMapping("api/list") //路由注解 请求该类的url
  17.  
  18. public List<com.example.vue.domain.List> list() {
  19. return listService.queryAll();
  20. }
  21.  
  22. @RequestMapping(value = "api/name", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  23. public List<com.example.vue.domain.List> name( @RequestBody Map<String, String> data ) {
  24. String name = data.get("name");
  25. if (!name.equals("")) {
  26. return listService.queryByName(name);
  27. } else {
  28. return listService.queryAll();
  29. }
  30.  
  31. }
  32.  
  33. @RequestMapping(value = "api/addList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  34. public int addList( @RequestBody Map<String, String> data ) {
  35. com.example.vue.domain.List list = new com.example.vue.domain.List();
  36. String name = data.get("name");
  37. String sex = Integer.parseInt(data.get("sex")) == 0 ? "女" : "男";
  38. String age = data.get("age");
  39. String birthday = data.get("birth");
  40. String address = data.get("address");
  41. list.setName(name);
  42. list.setSex(sex);
  43. list.setAge(Integer.parseInt(age));
  44. list.setBirthday(birthday);
  45. list.setAddress(address);
  46. return listService.addList(list);
  47. }
  48.  
  49. @RequestMapping(value = "api/delList",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
  50.  
  51. public int delList(@RequestBody Map<String,String> data){
  52. int id = Integer.parseInt(data.get("id"));
  53. System.out.println(id);
  54. int num = listService.delList(id);
  55. System.out.println(num);
  56. return num;
  57. }
  58. // @RequestMapping(value = "api/findAge",method = RequestMethod.POST,produces = "json/application;charset=UTF-8")
  59.  
  60. // public com.example.vue.domain.List findAge (){
  61. //
  62. // }

domain(bean)/List.java

  1. package com.example.vue.domain;
  2.  
  3. import java.util.Date;
  4.  
  5. public class List {
  6. private int id;
  7. private String name;
  8. private String sex;
  9. private int age;
  10. private String birthday;
  11. private String address;
  12.  
  13. // setter
  14.  
  15. public void setId( int id ) {
  16. this.id = id;
  17. }
  18.  
  19. public void setName( String name ) {
  20. this.name = name;
  21. }
  22.  
  23. public void setSex( String sex ) {
  24. this.sex = sex;
  25. }
  26.  
  27. public void setAge( int age ) {
  28. this.age = age;
  29. }
  30.  
  31. public void setBirthday( String birthday ) {
  32. this.birthday = birthday;
  33. }
  34.  
  35. public void setAddress( String address ) {
  36. this.address = address;
  37. }
  38. // getter
  39.  
  40. public int getId() {
  41. return id;
  42. }
  43.  
  44. public String getName() {
  45. return name;
  46. }
  47.  
  48. public String getSex() {
  49. return sex;
  50. }
  51.  
  52. public int getAge() {
  53. return age;
  54. }
  55.  
  56. public String getBirthday() {
  57. return birthday;
  58. }
  59.  
  60. public String getAddress() {
  61. return address;
  62. }
  63. }

service/ListService.java

  1. package com.example.vue.service;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5.  
  6. import java.util.List;
  7.  
  8. @Service
  9. public interface ListService {
  10. @Autowired
  11. List<com.example.vue.domain.List> queryAll();
  12. List<com.example.vue.domain.List> queryByName(String name);
  13. int addList( com.example.vue.domain.List list );
  14. int delList(int id);
  15. }

service/impl/ListServiceImpl.java

  1. package com.example.vue.service.impl;
  2.  
  3. import com.example.vue.dao.ListDao;
  4. import com.example.vue.service.ListService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7.  
  8. import java.util.List;
  9.  
  10. @Service("ListService")
  11. public class ListServiceImpl implements ListService {
  12. @Autowired
  13.  
  14. private ListDao listDao;
  15.  
  16. public List<com.example.vue.domain.List> queryAll(){
  17. return listDao.findAll();
  18. }
  19.  
  20. public List<com.example.vue.domain.List> queryByName( String name){
  21. return listDao.queryName(name);
  22. }
  23. public int addList( com.example.vue.domain.List list ){
  24. return listDao.insertList(list);
  25. }
  26. public int delList(int id){
  27. return listDao.deleteList(id);
  28. }
  29. }

dao/ListDao.java

  1. package com.example.vue.dao;
  2.  
  3. import org.apache.ibatis.annotations.Mapper;
  4. import org.apache.ibatis.annotations.Param;
  5. import org.springframework.stereotype.Repository;
  6.  
  7. import java.util.List;
  8.  
  9. @Mapper
  10. @Repository
  11. public interface ListDao {
  12. List<com.example.vue.domain.List> findAll();
  13. List<com.example.vue.domain.List> queryName( @Param ("name") String name);
  14. int insertList( com.example.vue.domain.List list );
  15. int deleteList(@Param("id") int id);
  16. }

application.yml:

  1. # DATASOURCE 数据库配置
  2. spring:
  3. datasource:
  4. url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&useSSL=true
  5. username: root
  6. password: 123456
  7. driver-class-name: com.mysql.jdbc.Driver
  8.  
  9. # MyBatis
  10. mybatis:
  11. typeAliasesPackage: com.example.vue.dao.*.dao
  12. mapperLocations: classpath:/mapper/*.xml
  13. # type-aliases-package: classpath:/com.example.vue.domai ,mn.User
  14. # configLocation: classpath:/mybatis.xml
  15. # typeAliasesPackage:
  16.  
  17. # 配置Tomcat编码为UTF_8
  18. server:
  19. tomcat:
  20. uri-encoding: utf-8

pom.xml:

  1. <!--配置MySQL工具-->
  2. <dependency>
  3. <groupId>mysql</groupId>
  4. <artifactId>mysql-connector-java</artifactId>
  5. <version>5.1.41</version>
  6. <scope>runtime</scope>
  7. </dependency>
  8. <!--springboot和mybatis集成中间件-->
  9. <dependency>
  10. <groupId>org.mybatis.spring.boot</groupId>
  11. <artifactId>mybatis-spring-boot-starter</artifactId>
  12. <version>${mybatis.version}</version>
  13. </dependency>

mapper/ListMapper.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4.  
  5. <mapper namespace="com.example.vue.dao.ListDao">
  6. <!-- 查询所有用户-->
  7. <select id="findAll" resultMap="listResult">SELECT * FROM list</select>
  8. <!-- 通过name查询用户-->
  9. <select id="queryName" resultMap="listResult">SELECT * FROM list where name = #{name}</select>
  10. <resultMap id="listResult" type="com.example.vue.domain.List">
  11. <result column="id" property="id"/>
  12. <result column="name" property="name"/>
  13. <result column="sex" property="sex"/>
  14. <result column="age" property="age"/>
  15. <result column="birthday" property="birthday"/>
  16. <result column="address" property="address"/>
  17. </resultMap>
  18. <insert id="insertList" parameterType="List">
  19. insert into list(name,sex,age,birthday,address) values (#{name},#{sex},#{age},#{birthday},#{address})
  20. </insert>
  21.  
  22. <delete id="deleteList" parameterType="List">
  23. delete from list where id = #{id}
  24. </delete>
  25. </mapper>

以上就是我的一个项目后台的大致目录结构
后台项目源码地址:https://github.com/wly13/vue-admin-background-programe

在spring boot中,注解很重要,附录常用的注解

@SpringBootApplication:申明让spring boot自动给程序进行必要的配置,这个配置等同于:

@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置。

@ResponseBody:表示该方法的返回结果直接写入HTTP response body中,一般在异步获取数据时使用,用于构建RESTful的api。在使用@RequestMapping后,返回值通常解析为跳转路径,加上@esponsebody后返回结果不会被解析为跳转路径,而是直接写入HTTP response body中。比如异步获取json数据,加上@Responsebody后,会直接返回json数据。该注解一般会配合@RequestMapping一起使用。示例代码:

@Controller:用于定义控制器类,在spring项目中由控制器负责将用户发来的URL请求转发到对应的服务接口(service层),一般这个注解在类中,通常方法需要配合注解@RequestMapping。示例代码:

@RestController:用于标注控制层组件(如struts中的action),@ResponseBody和@Controller的合集。示例代码:

@RequestMapping:提供路由信息,负责URL到Controller中的具体函数的映射。

@EnableAutoConfiguration:SpringBoot自动配置(auto-configuration):尝试根据你添加的jar依赖自动配置你的Spring应用。例如,如果你的classpath下存在HSQLDB,并且你没有手动配置任何数据库连接beans,那么我们将自动配置一个内存型(in-memory)数据库”。你可以将@EnableAutoConfiguration或者@SpringBootApplication注解添加到一个@Configuration类上来选择自动配置。如果发现应用了你不想要的特定自动配置类,你可以使用@EnableAutoConfiguration注解的排除属性来禁用它们。

@ComponentScan:表示将该类自动发现扫描组件。个人理解相当于,如果扫描到有@Component、@Controller、@Service等这些注解的类,并注册为Bean,可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。如果没有配置的话,Spring Boot会扫描启动类所在包下以及子包下的使用了@Service,@Repository等注解的类。

@Configuration:相当于传统的xml配置文件,如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件。

@Import:用来导入其他配置类。

@ImportResource:用来加载xml配置文件。

@Autowired:自动导入依赖的bean

@Service:一般用于修饰service层的组件

@Repository:使用@Repository注解可以确保DAO或者repositories提供异常转译,这个注解修饰的DAO或者repositories类会被ComponetScan发现并配置,同时也不需要为它们提供XML配置项。

@Bean:用@Bean标注方法等价于XML中配置的bean。

@Value:注入Spring boot application.properties配置的属性的值。示例代码:

@Inject:等价于默认的@Autowired,只是没有required属性;

@Component:泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

@Bean:相当于XML中的,放在方法的上面,而不是类,意思是产生一个bean,并交给spring管理。

@AutoWired:自动导入依赖的bean。byType方式。把配置好的Bean拿来用,完成属性、方法的组装,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。当加上(required=false)时,就算找不到bean也不报错。

@Qualifier:当有多个同一类型的Bean时,可以用@Qualifier(“name”)来指定。与@Autowired配合使用。@Qualifier限定描述符除了能根据名字进行注入,但能进行更细粒度的控制如何选择候选者,具体使用方式如下:

@Resource(name=”name”,type=”type”):没有括号内内容的话,默认byName。与@Autowired干类似的事。

数据库搭建

数据库采用的是wampserver中的mysql,下载wampserver,安装好后启动,等到图标变绿后,点击phpMyAdmin,然后就可以在网页上搭建数据库,当然你也可以选择通过命令来创建数据库以及相关数据 ps:数据库中的数据存放于后台系统中的database目录下,可以直接放到wampserver中的mysql下的data目录下然后使用,

一个vue管理系统的初步搭建总结的更多相关文章

  1. 利用 vue-cli 构建一个 Vue 项目

    一.项目初始构建 现在如果要构建一个 Vue 的项目,最方便的方式,莫过于使用官方的 vue-cli . 首先,咱们先来全局安装 vue-cli ,打开命令行工具,输入以下命令: $ npm inst ...

  2. vue.js开发环境搭建以及创建一个vue实例

    Vue.js 是一套构建用户界面的渐进式框架.Vue 只关注视图层, 采用自底向上增量开发的设计.Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件. 在使用 vue.js ...

  3. 如何搭建一个VUE项目

    搭建环境 搭建node环境 下载 1.进入node.js官方网站下载页,点击下图中框出位置,进行下载即可,当前版本为8.9.4,下载网址为:https://nodejs.org/zh-cn/downl ...

  4. 使用React全家桶搭建一个后台管理系统

    引子 学生时代为了掌握某个知识点会不断地做习题,做总结,步入岗位之后何尝不是一样呢?做业务就如同做习题,如果‘课后’适当地进行总结,必然更快地提升自己的水平. 由于公司采用的react+node的技术 ...

  5. 从零开始搭建一个vue.js的脚手架

    在谷歌工作的时候,我们要做很多界面的原型,要求快速上手,灵活运用,当时用的一些现有框架,比如angular,太笨重了——尤雨溪(Vue.js 作者) vue.js是现在一个很火的前端框架,官网描述其简 ...

  6. VUE系列一:VUE入门:搭建脚手架CLI(新建自己的一个VUE项目)

    一.VUE脚手架介绍 官方说明:Vue 提供了一个官方的 CLI,为单页面应用快速搭建 (SPA) 繁杂的脚手架.它为现代前端工作流提供了 batteries-included 的构建设置.只需要几分 ...

  7. vue-用Vue-cli从零开始搭建一个Vue项目

    Vue是近两年来比较火的一个前端框架(渐进式框架吧). Vue两大核心思想:组件化和数据驱动.组件化就是将一个整体合理拆分为一个一个小块(组件),组件可重复使用:数据驱动是前端的未来发展方向,释放了对 ...

  8. 如何搭建一个vue项目(完整步骤)

    参考资料 一.安装node环境 1.下载地址为:https://nodejs.org/en/ 2.检查是否安装成功:如果输出版本号,说明我们安装node环境成功 3.为了提高我们的效率,可以使用淘宝的 ...

  9. 搭建一个VUE项目

    搭建环境 搭建node环境 下载 1.进入node.js官方网站下载页,点击下图中框出位置,进行下载即可,当前版本为8.9.4,下载网址为:https://nodejs.org/zh-cn/downl ...

随机推荐

  1. python 同名变量引用

  2. oracle-Mount

    执行nomount的所有工作,另外附加数据结构并与这些数据结构进行交互.这时,oracle从控制文件中获得信息. 可以执行的任务是: 执行数据库的完全恢复操作 重命名数据文件 改变数据库的归档状态. ...

  3. 阿里云发布SaaS加速器,用宜搭,像搭积木一样搭应用

    宜搭让不会编码的人也能快速搭建SaaS应用,大幅提升研发效率. (图:阿里云智能产品管理部总经理马劲在2019阿里云峰会·北京现场进行宜搭应用搭建演示. ) 3月21日,在2019阿里云峰会·北京上, ...

  4. thinkphp5.0验证码使用

    如果没有安装验证码类,可在composer.json 文件的require里面添加 "topthink/think-captcha":"1.*",然后compo ...

  5. UVA_489:Hangman Judge

    Language:C++ 4.8.2 #include<stdio.h> #include<string.h> int main(void) { ]; ]; ]; ]; // ...

  6. 发布SaaS加速器:我们不做SaaS,我们只做SaaS生态的推进者和守护者

    摘要: 此次阿里云推出的SaaS加速器,涵盖商业中心.能力中心.技术中心三大板块,是阿里巴巴商业.能力和技术的一次合力输出:技术能力在这里沉淀为一个个模块,ISV和开发者只要通过简单的操作,写很少的代 ...

  7. Flask学习之五 用户登录

    英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins 中文翻译地址:http:// ...

  8. android service中stub作用是什么?

    AIDL(android 接口描述语言)是一个IDL语言,它可以生成一段代码,可以使在一个android设备上运行的两个进程使用内部通信进程进行交互.如果你需要在一个进程中(例如:在一个Activit ...

  9. Javascript中的定时调用函数setInterval()和setTimeout()

    首先介绍这两个函数 一.setInterval() 按照指定的周期来调用函数或表达式,执行多次.(时间单位:ms) timer = setInterval("content =documen ...

  10. Intellj IDEA14上用Debug启动项目启动不了:Unable to open debugger port: java.net.SocketException "socket closed"

    详情见上图更清晰 15:11:10 Application Server was not connected before run configuration stop, reason: Unable ...