2.0 分析
2.1 环境搭建
2.1.1 数据库
CREATEDATABASEzx_edu_course; USEzx_edu_course; CREATETABLE`edu_subject` ( `id`VARCHAR(32) NOTNULLPRIMARYKEYCOMMENT'课程科目ID', `title`VARCHAR(10) NOTNULLCOMMENT'科目名称', `parent_id`VARCHAR(32) NOTNULLDEFAULT'0'COMMENT'父ID', `sort`INT(10) NOTNULLDEFAULT0COMMENT'排序字段', `gmt_create`DATETIMENOTNULLCOMMENT'创建时间', `gmt_modified`DATETIMENOTNULLCOMMENT'更新时间') COMMENT='课程科目'; INSERTINTO`edu_subject`VALUES ('1', '云计算', '0', 0, '2020-06-26 09:41:21', '2020-02-20 23:25:58'); INSERTINTO`edu_subject`VALUES ('2', '系统/运维', '0', 0, '2020-02-20 23:29:59', '2020-02-20 23:29:59'); INSERTINTO`edu_subject`VALUES ('3', '数据库', '0', 0, '2020-02-20 23:30:13', '2020-02-20 23:30:13'); INSERTINTO`edu_subject`VALUES ('4', '服务器', '0', 0, '2020-02-20 23:30:19', '2020-02-20 23:30:19'); INSERTINTO`edu_subject`VALUES ('5', 'MySQL', '3', 1, '2020-02-20 23:30:13', '2020-02-20 23:30:13'); INSERTINTO`edu_subject`VALUES ('6', 'Oracle', '3', 2, '2020-02-20 23:30:13', '2020-02-20 23:30:13'); INSERTINTO`edu_subject`VALUES ('7', 'Tomcat', '4', 1, '2020-02-20 23:30:13', '2020-02-20 23:30:13'); INSERTINTO`edu_subject`VALUES ('8', 'Nginx ', '4', 2, '2020-02-20 23:30:13', '2020-02-20 23:30:13'); INSERTINTO`edu_subject`VALUES ('9', 'MySQL优化', '5', 1, '2020-02-20 23:30:13', '2020-02-20 23:30:13');
2.1.2 后端:环境
- 项目名:zx-service-course
- pom文件
<dependencies><!--web起步依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--nacos客户端--><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></dependency><!--nacos服务发现--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--swagger2--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId></dependency><!--feign远程调用--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><!--测试--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!--mybatisplus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>${mybatis.plus.version}</version></dependency><!--mysql驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!--自定义项目--><dependency><groupId>com.czxy.zx</groupId><artifactId>zx-common31</artifactId></dependency><dependency><groupId>com.czxy.zx</groupId><artifactId>zx-domain31</artifactId></dependency><!--redis启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!--JavaMail启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency><!--MQ启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!--fastjson--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><!--开发者工具--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.0.5</version></dependency></dependencies>yml文件#服务端口号server: port: 9020#服务名spring: application: name: course-servicedatasource: driverClassName: com.mysql.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/zx_edu_course?useUnicode=true&characterEncoding=utf8username: rootpassword: 1234druid: #druid连接池配置initial-size: 1#初始化连接池大小min-idle: 1#最小连接数max-active: 20#最大连接数test-on-borrow: true#获取连接时候验证,会影响性能cloud: nacos: discovery: server-addr: 127.0.0.1:8848#nacos服务地址redis: database: 0#数据库索引,取值0-15,表示16个库可选择host: 127.0.0.1#服务器地址port: 6379#服务器连接端口号mail: host: smtp.126.com#发送邮件服务器username: itcast_lt .com#账号password: 1qaz2wsx#密码default-encoding: UTF-8#默认编码时rabbitmq: host: 127.0.0.1port: 5672username: guestpassowrd: guestvirtualHost: /devtools: restart: enabled: true#设置开启热部署additional-paths: src/main/java#重启目录exclude: WEB-INF/**freemarker:cache: false #页面不加载缓存,修改即时生效#开启log4j打印SQL语句logging:level:com:czxy:mapper: debug# mp日志打印mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl启动类package com.czxy.zx;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.openfeign.EnableFeignClients;/*** @author 桐叔* @email liangtong@itcast.cn*/publicclassCourseServiceApplication { publicstaticvoidmain(String[] args) { SpringApplication.run(CourseServiceApplication.class,args); } }
2.1.3 后端:基本模块
创建JavaBeanpackagecom.czxy.zx.domain; importcom.baomidou.mybatisplus.annotation.IdType; importcom.baomidou.mybatisplus.annotation.TableField; importcom.baomidou.mybatisplus.annotation.TableId; importcom.baomidou.mybatisplus.annotation.TableName; importcom.fasterxml.jackson.annotation.JsonFormat; importlombok.Data; importorg.springframework.format.annotation.DateTimeFormat; importjava.util.ArrayList; importjava.util.Date; importjava.util.List; /*** 课程科目(EduSubject)表实体类** @author 桐叔*/"edu_subject") (publicclassEduSubject{ type=IdType.ASSIGN_UUID) (//课程科目IDprivateStringid; //科目名称privateStringtitle; //父IDprivateStringparentId; //排序字段privateIntegersort; //创建时间pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") (privateDategmtCreate; //更新时间pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") (privateDategmtModified; exist=false) (JsonInclude.Include.NON_EMPTY) //生成json数据,不包含空元素 (privateList<EduSubject>children=newArrayList<>(); }
packagecom.czxy.zx.course.mapper; importcom.baomidou.mybatisplus.core.mapper.BaseMapper; importcom.czxy.zx.domain.EduSubject; importorg.apache.ibatis.annotations.Mapper; /*** @author 桐叔* @email liangtong@itcast.cn*/publicinterfaceEduSubjectMapperextendsBaseMapper<EduSubject> { }
接口packagecom.czxy.zx.course.service; importcom.baomidou.mybatisplus.extension.service.IService; importcom.czxy.zx.domain.EduSubject; /*** @author 桐叔* @email liangtong@itcast.cn*/publicinterfaceEduSubjectServiceextendsIService<EduSubject> { } 实现类packagecom.czxy.zx.course.service.impl; importcom.baomidou.mybatisplus.extension.service.impl.ServiceImpl; importcom.czxy.zx.course.mapper.EduSubjectMapper; importcom.czxy.zx.course.service.EduSubjectService; importcom.czxy.zx.domain.EduSubject; importorg.springframework.stereotype.Service; importorg.springframework.transaction.annotation.Transactional; /*** @author 桐叔* @email liangtong@itcast.cn*/publicclassEduSubjectServiceImplextendsServiceImpl<EduSubjectMapper, EduSubject>implementsEduSubjectService { }
packagecom.czxy.zx.course.controller; importcom.czxy.zx.course.service.EduSubjectService; importorg.springframework.web.bind.annotation.RequestMapping; importorg.springframework.web.bind.annotation.RestController; importjavax.annotation.Resource; /*** @author 桐叔* @email liangtong@itcast.cn*/"/subject") (publicclassEduSubjectController { privateEduSubjectServiceeduSubjectService; }