前后端项目-part02

文章目录

  • 4 课程分类树
    • 4.1 需求展示
    • 4.2 后端开发
      • 4.2.1 添加工具类
      • 4.2.2 添加依赖
      • 4.2.3 创建实体类
      • 4.2.4 创建Mapper
      • 4.2.5 创建Service
      • 4.2.6 创建Controller
      • 4.2.7创建启动类
      • 4.2.8创建yml文件
      • 4.2.9测试
    • 4.3 前端开发
      • 4.3.1 树形控件测试
      • 4.3.2 替换测试数据
    • 4.4 利用ThreadLocal实现共享用户信息
      • 4.4.1创建工具类
      • 4.4.2 改造用户登录
    • 4.5 添加SpringMVC拦截器
      • 4.5.1 创建拦截器
      • 4.5.2 注册拦截器
      • 4.5.3 使用拦截器
      • 4.5.4 测试
  • 5课程信息管理
    • 5.1 效果图
      • 5.1.1 前台
      • 5.1.2 项目结构
    • 5.2 前台开发
      • 5.2.1 修改navment.vue-添加新菜单
      • 5.2.2 修改router/index.js-配置新菜单
      • 5.2.3 创建api/Course.js
      • 5.2.4 pages下创建新组件course.vue
      • 5.2.5 测试
    • 5.3 后台开发
      • 5.3.1 创建实体类
      • 5.3.2 创建CourseMapper
      • 5.3.3 创建CourseService
      • 5.3.4 CourseController
      • 5.3.5 创建启动类
      • 5.3.6 修改pom,添加依赖
      • 5.3.7 创建配置文件
    • 5.4 准备下拉框数据
      • 5.4.1 一级分类
        • 5.4.1.1 创建Options
        • 5.4.1.2 修改CategoryService
        • 5.4.1.3 修改CategoryController
        • 5.4.1.4 测试
        • 5.4.1.5 创建basic.js
        • 5.4.1.6修改course.vue
        • 5.4.1.7测试
        • 5.4.1.8 Bytheway 修改basic.js,修改welcom.vue,测试
      • 5.4.2 二级分类
        • 5.4.2.1 后台开发
        • 5.4.2.1 前台开发
        • 5.4.2.3 测试
      • 5.4.3 课程等级 & 教学模式
        • 5.4.3.1 创建实体类Dictionary
        • 5.4.3.2 创建CategoryMapper
        • 5.4.3.3 创建DictionaryService
        • 5.4.3.4 创建DictionaryController
        • 5.4.3.5 后台测试
        • 5.4.3.6 前台开发
        • 5.4.3.7 前后端测试

4 课程分类树

4.1 需求展示

在这里插入图片描述

4.2 后端开发

在这里插入图片描述

4.2.1 添加工具类

在这里插入图片描述

4.2.2 添加依赖

在这里插入图片描述

4.2.3 创建实体类

package com.zx.category.entity;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.io.Serializable;
//课程分类实体
@TableName("tb_category")
@NoArgsConstructor
@AllArgsConstructor
@Data
@ToString
@Accessors(chain = true)
public class Category implements Serializable {private String id;//编号private String name;//名称private String label;//展示名称private String parentid;//父idprivate Integer is_show;//是否展现,1是0不是private Integer orderby;//排序规则private Integer is_leaf;//是否叶子,1是0不是}

4.2.4 创建Mapper

package com.zx.category.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zx.category.entity.Category;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
}

4.2.5 创建Service

package com.zx.category.service;import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.tree.Node;
import com.zx.category.entity.Category;
import com.zx.category.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.List;@Service
public class CategoryService extends ServiceImpl<CategoryMapper, Category> {@Autowiredprivate CategoryMapper categoryMapper;//查询课程分类三级菜单public List<Node> getTree() {//存放所有维护好的数据List<Node> tree = new ArrayList<>();//查询1级菜单->SELECT * from tb_category where parentid=0 and is_show=1QueryWrapper qw1 = new QueryWrapper();//封装查询条件qw1.eq("parentid", 0);//父节点id为0qw1.eq("is_show", 1);//需要展示List<Category> level1 = categoryMapper.selectList(qw1);//查到所有1级菜单for (Category c : level1) {Node node1 = new Node();//1级节点node1.setValue(c.getId());node1.setLabel(c.getLabel());
//            node1.setChildren();//1级菜单的子菜单是2级菜单,现在需要查询所有2级菜单//查询2级菜单,并添加为1级菜单的children->SELECT * from tb_category where parentid='1' and is_show=1 order by orderbyQueryWrapper<Category> qw2 = new QueryWrapper<>();qw2.eq("parentid", "1");qw2.eq("is_show", 1);qw2.orderByAsc("orderby");//排序List<Category> level2 = categoryMapper.selectList(qw2);//查到所有2级//存2级节点List<Node> children1 = new ArrayList<>();for (Category c2 : level2) {Node node2 = new Node();//2级节点node2.setValue(c2.getId());node2.setLabel(c2.getLabel());
//                node2.setChildren();//2级菜单的子菜单,继续查3级...//查询3级菜单,并添加为2级菜单的children->SELECT * from tb_category where parentid='1-1' and is_show=1 order by orderbyQueryWrapper<Category> qw3 = new QueryWrapper<>();qw3.eq("parentid", c2.getId());qw3.eq("is_show", 1);qw3.orderByAsc("orderby");//排序List<Category> level3 = categoryMapper.selectList(qw3);//查到所有3级//存3级节点List<Node> children2 = new ArrayList<>();for (Category c3 : level3) {Node node3 = new Node();//2级节点node3.setValue(c3.getId());node3.setLabel(c3.getLabel());
//                    node3.setChildren();//3级菜单是叶子节点,他没有子节点children2.add(node3);//TODO 1.把查出来的3级节点,添加为2级节点的children}children1.add(node2); //TODO 2.把查出来的2级节点,添加为1级节点的childrennode2.setChildren(children2);//TODO 3.把children2添加给node2}node1.setChildren(children1);//TODO 4.把children1添加给node1tree.add(node1);//准备返回数据}return tree;}
}

4.2.6 创建Controller

package com.zx.category.controller;import com.common.tree.Node;
import com.zx.category.entity.Category;
import com.zx.category.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
@CrossOrigin
@RequestMapping("/basic/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;@RequestMapping("/getTree")//查询课程分类三级菜单public List<Node> getTree() {return categoryService.getTree();}}

4.2.7创建启动类

package com.zx.category;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class BasicRunApp {public static void main(String[] args) {SpringApplication.run(BasicRunApp.class);}
}

4.2.8创建yml文件

server:port: 9999
spring:application:name: zx-basic-servicedatasource:type: com.zaxxer.hikari.HikariDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/zx-basic?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghaiusername: rootpassword: roothikari:minimum-idle: 5maximum-pool-size: 15auto-commit: trueidle-timeout: 30000pool-name: DatebookHikariCPmax-lifetime: 1800000connection-timeout: 30000connection-test-query: SELECT 1
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper-locations: classpath:/mapper/*.xmltype-aliases-package: com.zx.category.entity

4.2.9测试

在这里插入图片描述

4.3 前端开发

4.3.1 树形控件测试

拿来主义,找到elementui官网的实例代码,一整个直接拷贝到welcome.vue里,启动服务测试效果
在这里插入图片描述

<template><h2>欢迎您来到我们的MOOC世界,开始您的技术学习之旅</h2><a href="https://blog.csdn.net/u012932876/article/details/118487949" target="_blank"class="button">java学习路径 官网</a><!-- 树形控件 --><el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree><div style="padding-top: 20px;"><img src='/images/info.png'/></div></template><script >export default {data() {return {data: [{label: '一级 1',children: [{label: '二级 1-1',children: [{label: '三级 1-1-1'}]}]}, {label: '一级 2',children: [{label: '二级 2-1',children: [{label: '三级 2-1-1'}]}, {label: '二级 2-2',children: [{label: '三级 2-2-1'}]}]}, {label: '一级 3',children: [{label: '二级 3-1',children: [{label: '三级 3-1-1'}]}, {label: '二级 3-2',children: [{label: '三级 3-2-1'}]}]}],defaultProps: {children: 'children',label: 'label'}};},methods: {handleNodeClick(data) {console.log(data);}}};
</script><style scoped>a.button {background-color: #4CAF50;padding: 6px 16px 7px 16px;font-size: 14px;color: white;text-align: center;border: none;cursor: pointer;border-radius: 4px;margin-right: 20px;text-decoration:none;}a.button:hover {background-color: #3e8e41;}
</style>

4.3.2 替换测试数据

把后端返回的JSON串,直接替换掉data
在这里插入图片描述

<template><h2>欢迎您来到我们的MOOC世界,开始您的技术学习之旅</h2><a href="https://blog.csdn.net/u012932876/article/details/118487949" target="_blank"class="button">java学习路径 官网</a><!-- 树形控件 --><el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree><div style="padding-top: 20px;"><img src='/images/info.png'/></div></template><script >export default {data() {return {data:[{"value": "1","label": "根结点","children": [{"value": "1-1","label": "前端开发","children": [{"value": "1-1-2","label": "JavaScript","children": null},{"value": "1-1-3","label": "jQuery","children": null},{"value": "1-1-4","label": "ExtJS","children": null},{"value": "1-1-5","label": "AngularJS","children": null},{"value": "1-1-6","label": "ReactJS","children": null},{"value": "1-1-7","label": "Bootstrap","children": null},{"value": "1-1-8","label": "Node.js","children": null},{"value": "1-1-9","label": "Vue","children": null},{"value": "1-1-10","label": "其它","children": null}]},{"value": "1-2","label": "移动开发","children": [{"value": "1-2-1","label": "微信开发","children": null},{"value": "1-2-2","label": "iOS","children": null},{"value": "1-2-3","label": "手游开发","children": null},{"value": "1-2-4","label": "Swift","children": null},{"value": "1-2-5","label": "Android","children": null},{"value": "1-2-6","label": "ReactNative","children": null},{"value": "1-2-7","label": "Cordova","children": null},{"value": "1-2-8","label": "其它","children": null}]},{"value": "1-3","label": "编程开发","children": [{"value": "1-3-1","label": "C/C++","children": null},{"value": "1-3-2","label": "Java","children": null},{"value": "1-3-3","label": ".NET","children": null},{"value": "1-3-4","label": "Objective-C","children": null},{"value": "1-3-5","label": "Go语言","children": null},{"value": "1-3-6","label": "Python","children": null},{"value": "1-3-7","label": "Ruby/Rails","children": null},{"value": "1-3-8","label": "其它","children": null}]},{"value": "1-4","label": "数据库","children": [{"value": "1-4-1","label": "Oracle","children": null},{"value": "1-4-2","label": "MySQL","children": null},{"value": "1-4-3","label": "SQL Server","children": null},{"value": "1-4-4","label": "DB2","children": null},{"value": "1-4-5","label": "NoSQL","children": null},{"value": "1-4-6","label": "Mongo DB","children": null},{"value": "1-4-7","label": "Hbase","children": null},{"value": "1-4-8","label": "数据仓库","children": null},{"value": "1-4-9","label": "其它","children": null}]},{"value": "1-5","label": "人工智能","children": [{"value": "1-5-1","label": "机器学习","children": null},{"value": "1-5-2","label": "深度学习","children": null},{"value": "1-5-3","label": "语音识别","children": null},{"value": "1-5-4","label": "计算机视觉","children": null},{"value": "1-5-5","label": "NLP","children": null},{"value": "1-5-6","label": "强化学习","children": null},{"value": "1-5-7","label": "其它","children": null}]},{"value": "1-6","label": "云计算/大数据","children": [{"value": "1-6-1","label": "Spark","children": null},{"value": "1-6-2","label": "Hadoop","children": null},{"value": "1-6-3","label": "OpenStack","children": null},{"value": "1-6-4","label": "Docker/K8S","children": null},{"value": "1-6-5","label": "云计算基础架构","children": null},{"value": "1-6-6","label": "虚拟化技术","children": null},{"value": "1-6-7","label": "云平台","children": null},{"value": "1-6-8","label": "ELK","children": null},{"value": "1-6-9","label": "其它","children": null}]},{"value": "1-7","label": "UI设计","children": [{"value": "1-7-1","label": "Photoshop","children": null},{"value": "1-7-2","label": "3Dmax","children": null},{"value": "1-7-3","label": "Illustrator","children": null},{"value": "1-7-4","label": "Flash","children": null},{"value": "1-7-5","label": "Maya","children": null},{"value": "1-7-6","label": "AUTOCAD","children": null},{"value": "1-7-7","label": "UG","children": null},{"value": "1-7-8","label": "SolidWorks","children": null},{"value": "1-7-9","label": "CorelDraw","children": null},{"value": "1-7-10","label": "InDesign","children": null},{"value": "1-7-11","label": "Pro/Engineer","children": null},{"value": "1-7-12","label": "Cinema 4D","children": null},{"value": "1-7-13","label": "3D Studio","children": null},{"value": "1-7-14","label": "After Effects(AE)","children": null},{"value": "1-7-15","label": "原画设计","children": null},{"value": "1-7-16","label": "动画制作","children": null},{"value": "1-7-17","label": "Dreamweaver","children": null},{"value": "1-7-18","label": "Axure","children": null},{"value": "1-7-19","label": "其它","children": null}]},{"value": "1-8","label": "游戏开发","children": [{"value": "1-8-1","label": "Cocos","children": null},{"value": "1-8-2","label": "Unity3D","children": null},{"value": "1-8-3","label": "Flash","children": null},{"value": "1-8-4","label": "SpriteKit 2D","children": null},{"value": "1-8-5","label": "Unreal","children": null},{"value": "1-8-6","label": "其它","children": null}]},{"value": "1-9","label": "智能硬件/物联网","children": [{"value": "1-9-1","label": "无线通信","children": null},{"value": "1-9-2","label": "电子工程","children": null},{"value": "1-9-3","label": "Arduino","children": null},{"value": "1-9-4","label": "体感技术","children": null},{"value": "1-9-5","label": "智能硬件","children": null},{"value": "1-9-6","label": "驱动/内核开发","children": null},{"value": "1-9-7","label": "单片机/工控","children": null},{"value": "1-9-8","label": "WinCE","children": null},{"value": "1-9-9","label": "嵌入式","children": null},{"value": "1-9-10","label": "物联网技术","children": null},{"value": "1-9-11","label": "其它","children": null}]},{"value": "1-10","label": "研发管理","children": [{"value": "1-10-1","label": "敏捷开发","children": null},{"value": "1-10-2","label": "软件设计","children": null},{"value": "1-10-3","label": "软件测试","children": null},{"value": "1-10-4","label": "研发管理","children": null},{"value": "1-10-5","label": "其它","children": null}]},{"value": "1-11","label": "系统运维","children": [{"value": "1-11-1","label": "Linux","children": null},{"value": "1-11-2","label": "Windows","children": null},{"value": "1-11-3","label": "UNIX","children": null},{"value": "1-11-4","label": "Mac OS","children": null},{"value"

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2813422.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

【Spring底层原理高级进阶】基于Spring Boot和Spring WebFlux的实时推荐系统的核心:响应式编程与 WebFlux 的颠覆性变革

&#x1f389;&#x1f389;欢迎光临&#x1f389;&#x1f389; &#x1f3c5;我是苏泽&#xff0c;一位对技术充满热情的探索者和分享者。&#x1f680;&#x1f680; &#x1f31f;特别推荐给大家我的最新专栏《Spring 狂野之旅&#xff1a;底层原理高级进阶》 &#x1f680…

安达发APS|多分厂多车间协同排产软件

多分厂多车间协同排产软件可以帮助各个分厂和车间之间实现信息的共享和协同工作&#xff0c;从而提高生产效率、降低成本、提高产品质量。那么&#xff0c;如何选择一款合适的多分厂多车间协同排产软件呢&#xff1f;本文将从以下几个方面进行详细介绍。 1. 功能需求 首先&…

Vue实现登录保存token并校验实现保存登录状态

文章目录 一、登录vue二、路由index 一、登录vue <script> import request from "/axios/baseURL"; import router from "/router";// 接口数据初始化 const FORM_DATA {userName: "",password: "", }; export default {data(…

opencv图像处理(3)

1.图像平滑 1.1图像噪声 由于图像采集、处理、传输等过程不可避免的会受到噪声的污染&#xff0c;妨碍人们对图像理解及分析处理。常见的图像噪声有高斯噪声、椒盐噪声等。 1.1.1椒盐噪声 椒盐噪声也称为脉冲噪声&#xff0c;是图像中经常见到的一种噪声&#xff0c;它是一…

CKA认证,开启您的云原生之旅!

在当今数字化时代&#xff0c;云计算已经成为企业和个人发展的关键技术。而获得CKA&#xff08;Certified Kubernetes Administrator&#xff09;认证&#xff0c;将是您在云原生领域迈出的重要一步。 CKA认证是由Kubernetes官方推出的权威认证&#xff0c;它旨在验证您在Kuber…

Java SpringBoot 创建项目工程输出 Hello World

Java SpringBoot 创建项目工程输出 Hello World 1、新建项目 2、创建 controller 3、编写 Hello World 代码 package com.zhong.demo01.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.Res…

音视频数字化(数字与模拟-电视)

上一篇文章【音视频数字化(数字与模拟-音频广播)】谈了音频的广播,这次我们聊电视系统,这是音频+视频的采集、传输、接收系统,相对比较复杂。 音频系统的广播是将声音转为电信号,再调制后发射出去,利用“共振”原理,收音机接收后解调,将音频信号还原再推动扬声器,我…

实战 vue3 使用百度编辑器ueditor

前言 在开发项目由于需求vue自带对编辑器不能满足使用&#xff0c;所以改为百度编辑器&#xff0c;但是在网上搜索发现都讲得非常乱&#xff0c;所以写一篇使用流程的文章 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 一、下载ueditor编辑器 一个“…

编译 Linux SDK源码包(基于迅为电子的RK3568开发板)

前言&#xff1a; 本文所使用的开发板是迅为电子的RK3568开发板&#xff0c;Linux源码包也是从的开发板自带资料中获取到的&#xff0c;有兴趣者可自行购买&#xff08;话说最近瑞芯微的芯片真的很火啊&#xff09; 目录 前言&#xff1a; SDK 包说明&#xff1a; SDK 包源…

如何使用Logstash搜集日志传输到es集群并使用kibana检测

引言&#xff1a;上一期我们进行了对Elasticsearch和kibana的部署&#xff0c;今天我们来解决如何使用Logstash搜集日志传输到es集群并使用kibana检测 目录 Logstash部署 1.安装配置Logstash &#xff08;1&#xff09;安装 &#xff08;2&#xff09;测试文件 &#xff…

Java+SpringBoot+Vue+MySQL:美食推荐系统的技术革新

✍✍计算机编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java实战 |…

2024-02-26(Spark,kafka)

1.Spark SQL是Spark的一个模块&#xff0c;用于处理海量结构化数据 限定&#xff1a;结构化数据处理 RDD的数据开发中&#xff0c;结构化&#xff0c;非结构化&#xff0c;半结构化数据都能处理。 2.为什么要学习SparkSQL SparkSQL是非常成熟的海量结构化数据处理框架。 学…

docker小知识:linux环境安装docker

安装必要软件包&#xff0c;执行如下命令 yum install -y yum-utils device-mapper-persistent-data lvm2目的是确保在安装 Docker 之前&#xff0c;系统已经安装了必要的软件包和服务&#xff0c;以支持 Docker 的正常运行。设置yum源&#xff0c;添加Docker官方的CentOS存储…

阿里云服务器2024年优惠价格表曝光,太可怕了!

2024阿里云服务器优惠活动政策整理&#xff0c;轻量2核2G3M服务器61元一年、2核4G4M带宽165元1年&#xff0c;云服务器4核16G10M带宽26元1个月、149元半年&#xff0c;阿里云ECS云服务器2核2G3M新老用户均可99元一年续费不涨价&#xff0c;企业用户2核4G5M带宽199元一年&#x…

微服务-微服务链路追踪组件Skywalking实战

自动化监控系统Prometheus&Grafana实战&#xff1a; 4 trem APM-性能监控项目班&#xff1a; https://vip.tulingxueyuan.cn/detail/p_602e574ae4b035d3cdb8f8fe/6 1. skywalking是什么 1.1 Skywalking主要功能特性 1.2 Skywalking整体架构 1.3 SkyWalking 环境搭建部…

2024热门UI设计工具推荐

最好的UI设计工具可以适应几乎每一个设计过程&#xff0c;并且有望满足您的创造性要求。但既然UI设计工具那么多&#xff0c;应该用什么工具呢&#xff1f; 在过去的几年里&#xff0c;Sketch和figma的结合一直是许多设计师的选择&#xff0c;但其他工具也提供了有竞争力的特点…

Redis 16种妙用

1、缓存 2、数据共享分布式 3、分布式锁 4、全局ID 5、计数器 6、限流 7、位统计 8、购物车 9、用户消息时间线timeline 10、消息队列 11、抽奖 12、点赞、签到、打卡 13、商品标签 14、商品筛选 15、用户关注、推荐模型 16、排行榜 1、缓存 String类型 例如&#xff1a;热点…

QT信号槽实现分析

1.宏定义 qt中引入了MOC来反射&#xff0c;编译阶段变成 MOC–>预处理–>编译–>汇编–>链接 1-1、Q_OBJECT 这个宏定义了一系列代码&#xff0c;包括元对象和处理的函数 #define Q_OBJECT \public: \QT_WARNING_PUSH \Q_OBJECT_NO_OVERRIDE_WARNING \static c…

【学海无涯】嵌入式工程师的100本专业书籍

001《大话数据结构》 002《鸟哥的 linux 私房菜》 003《疯狂 android 讲义》 004《第一行代码》 005《linux 内核设计与实现》 006《驱动设计开发》 007《linux 内核解密》 008《unix 环境高级编程》 009《linux 内核设计与实现》 010《essential C》 011《嵌入式 li…

CTFHub技能树web之XSS

在XSS系列的题目中&#xff0c;由于需要使用能够接受XSS数据的平台&#xff0c;并且由于使用的是CTFHub的模拟机器人点击我们的虚假URL&#xff0c;因此使用的XSS平台不能是自己本地搭建的&#xff0c;如果是本地的模拟点击的机器人将无法访问我们给的这个URL地址&#xff0c;也…