JsonResult ok(T data) {
+
+ JsonResult jsonResult = new JsonResult();
+ jsonResult.setCode(200);//code值是自行定义
+ jsonResult.setMsg("success");
+ jsonResult.setData(data);
+ return jsonResult;
+ }
+
+ public static JsonResult error() {
+
+ JsonResult jsonResult = new JsonResult();
+ jsonResult.setCode(500);
+ jsonResult.setMsg("fail");
+
+ return jsonResult;
+ }
+
+ public static JsonResult error(int code, String msg) {
+
+ JsonResult jsonResult = new JsonResult();
+ jsonResult.setCode(code);
+ jsonResult.setMsg(msg);
+
+ return jsonResult;
+ }
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/course/config/MyWebMvcConfig.java b/src/main/java/com/zhiyun/zhiyun03/course/config/MyWebMvcConfig.java
new file mode 100644
index 0000000..ebf4cd7
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/course/config/MyWebMvcConfig.java
@@ -0,0 +1,25 @@
+package com.zhiyun.zhiyun03.course.config;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+
+@Configuration
+public class MyWebMvcConfig extends WebMvcConfigurationSupport {
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/**").addResourceLocations(
+ "classpath:/static/");
+
+ // swagger静态资源相关
+ registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
+ "classpath:/META-INF/resources/");
+ registry.addResourceHandler("/webjars/**").addResourceLocations(
+ "classpath:/META-INF/resources/webjars/");
+ // 针对swagger自带的静态资源
+ registry.addResourceHandler("/swagger-ui/**").addResourceLocations(
+ "classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
+ super.addResourceHandlers(registry);
+ }
+
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/course/config/SwaggerConfig.java b/src/main/java/com/zhiyun/zhiyun03/course/config/SwaggerConfig.java
new file mode 100644
index 0000000..b13017a
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/course/config/SwaggerConfig.java
@@ -0,0 +1,112 @@
+package com.zhiyun.zhiyun03.course.config;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.models.auth.In;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.oas.annotations.EnableOpenApi;
+import springfox.documentation.service.*;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spi.service.contexts.SecurityContext;
+import springfox.documentation.spring.web.plugins.Docket;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Swagger3的接口配置
+ *
+ * http://localhost:8080/swagger-ui/index.html#/
+ */
+@Configuration
+@EnableOpenApi // swagger3使用的注解
+public class SwaggerConfig {
+
+ /**
+ * 是否开启swagger
+ */
+ // 注入常量值
+ @Value("${swagger.enabled}")
+ private boolean enabled;
+
+ /**
+ * 创建API
+ */
+ @Bean
+ public Docket createRestApi() {
+ return new Docket(DocumentationType.OAS_30)
+ // 是否启用Swagger
+ .enable(enabled)
+ // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
+ .apiInfo(apiInfo())
+ // 设置哪些接口暴露给Swagger展示
+ .select()
+ // 扫描所有有注解的api,用这种方式更灵活
+ .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
+ // 扫描指定包中的swagger注解
+ //.apis(RequestHandlerSelectors.basePackage("com.carpjump"))
+ // 扫描所有 .apis(RequestHandlerSelectors.any())
+ .paths(PathSelectors.any())
+ .build()
+ /* 设置安全模式,swagger可以设置访问token */
+ .securitySchemes(securitySchemes())
+ .securityContexts(securityContexts())
+ .pathMapping("/");
+ }
+
+ /**
+ * 安全模式,这里指定token通过请求头的token头传递
+ */
+ private List securitySchemes() {
+ List apiKeyList = new ArrayList();
+ apiKeyList.add(new ApiKey("token", "token", In.HEADER.toValue()));
+ return apiKeyList;
+ }
+
+ /**
+ * 安全上下文
+ */
+ private List securityContexts() {
+ List securityContexts = new ArrayList<>();
+ securityContexts.add(
+ SecurityContext.builder()
+ .securityReferences(defaultAuth())
+ .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
+ .build());
+ return securityContexts;
+ }
+
+ /**
+ * 默认的安全上引用
+ */
+ private List defaultAuth() {
+ AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
+ AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
+ authorizationScopes[0] = authorizationScope;
+ List securityReferences = new ArrayList<>();
+ securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
+ return securityReferences;
+ }
+
+ /**
+ * 添加摘要信息
+ */
+ private ApiInfo apiInfo() {
+ // 用ApiInfoBuilder进行定制
+ return new ApiInfoBuilder()
+ // 设置标题
+ .title("app接口文档")
+ // 描述
+ .description("具体包括XXX,XXX模块...")
+ // 作者信息
+ .contact(new Contact("qfedu", null, null))
+ // 版本
+ .version("1.0.0")
+ .build();
+ }
+}
+
diff --git a/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java b/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java
new file mode 100644
index 0000000..0ddb10e
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/course/controller/CourseController.java
@@ -0,0 +1,73 @@
+package com.zhiyun.zhiyun03.course.controller;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.zhiyun.zhiyun03.course.common.JsonResult;
+import com.zhiyun.zhiyun03.course.entity.Course;
+
+import com.zhiyun.zhiyun03.course.service.CourseService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Api("课程")
+@RestController
+@RequestMapping("/api/course")
+public class CourseController {
+
+ @Autowired
+ private CourseService courseService;
+
+
+ @ApiOperation("查询课程")
+ @GetMapping("/selectAll")
+ public JsonResult selectAll(@RequestParam(value = "page", required = false,defaultValue = "1") Integer pageNum,
+ @RequestParam(value = "limit", required = false,defaultValue = "1") Integer pageSize){
+
+ PageHelper.startPage(pageNum,pageSize);
+ List courseList = courseService.selectAll();
+
+ PageInfo coursePageInfo = new PageInfo<>();
+
+ JsonResult jsonResult = JsonResult.ok();
+ jsonResult.setData(coursePageInfo.getList());
+ jsonResult.setCount(coursePageInfo.getTotal());
+ return jsonResult;
+ }
+
+
+ @ApiOperation("课程添加")
+ @PostMapping("/add")
+ public JsonResult addCourse(Course course){
+ courseService.addCourse(course);
+ return JsonResult.ok();
+ }
+
+// @ApiOperation("查询目录")
+// @PostMapping("/select")
+// public JsonResult selectDir(Directory directory){
+// courseService.se(course);
+// return JsonResult.ok();
+// }
+
+ @ApiOperation("删除课程")
+ @DeleteMapping("delById")
+ public JsonResult delCourseById(Integer id){
+ courseService.delCourseById(id);
+return JsonResult.ok();
+ }
+
+ @ApiOperation("更新课程")
+ @DeleteMapping("updateById")
+ public JsonResult updateById(Course course){
+ courseService.updateById(course);
+ return JsonResult.ok();
+ }
+
+
+
+
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java b/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java
new file mode 100644
index 0000000..dc3b083
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/course/service/CourseService.java
@@ -0,0 +1,15 @@
+package com.zhiyun.zhiyun03.course.service;
+
+import com.zhiyun.zhiyun03.course.entity.Course;
+
+import java.util.List;
+
+public interface CourseService {
+ public void addCourse(Course course);
+
+ void delCourseById(Integer id);
+
+ void updateById(Course course);
+
+ List selectAll();
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java b/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java
new file mode 100644
index 0000000..cbb3b52
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/course/service/impl/CourseServiceImpl.java
@@ -0,0 +1,36 @@
+package com.zhiyun.zhiyun03.course.service.impl;
+
+import com.zhiyun.zhiyun03.course.dao.CourseDAO;
+import com.zhiyun.zhiyun03.course.entity.Course;
+import com.zhiyun.zhiyun03.course.service.CourseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CourseServiceImpl implements CourseService {
+
+ @Autowired
+ private CourseDAO courseDAO;
+
+ @Override
+ public void addCourse(Course course) {
+ courseDAO.insert(course);
+ }
+
+ @Override
+ public void delCourseById(Integer id) {
+ courseDAO.deleteByPrimaryKey(id);
+ }
+
+ @Override
+ public void updateById(Course course) {
+ courseDAO.updateByPrimaryKey(course);
+ }
+
+ @Override
+ public List selectAll() {
+ return courseDAO.selectAll();
+ }
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/directory/controller/DirectoryController.java b/src/main/java/com/zhiyun/zhiyun03/directory/controller/DirectoryController.java
new file mode 100644
index 0000000..83059a3
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/directory/controller/DirectoryController.java
@@ -0,0 +1,33 @@
+package com.zhiyun.zhiyun03.directory.controller;
+
+import com.zhiyun.zhiyun03.course.common.JsonResult;
+import com.zhiyun.zhiyun03.directory.entity.Directory;
+import com.zhiyun.zhiyun03.directory.servcie.DirectoryService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api("目录")
+@RestController
+@RequestMapping("/api/directory")
+public class DirectoryController {
+ @Autowired
+ private DirectoryService directoryService;
+
+ @ApiOperation("添加目录")
+ @PostMapping("/add")
+ public JsonResult addDirectory(Directory directory){
+ directoryService.addDirectory(directory);
+ return JsonResult.ok();
+ }
+
+
+
+
+
+
+
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/directory/servcie/DirectoryService.java b/src/main/java/com/zhiyun/zhiyun03/directory/servcie/DirectoryService.java
new file mode 100644
index 0000000..5eb61ae
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/directory/servcie/DirectoryService.java
@@ -0,0 +1,7 @@
+package com.zhiyun.zhiyun03.directory.servcie;
+
+import com.zhiyun.zhiyun03.directory.entity.Directory;
+
+public interface DirectoryService {
+ void addDirectory(Directory directory);
+}
diff --git a/src/main/java/com/zhiyun/zhiyun03/directory/servcie/impl/DirectoryServiceImpl.java b/src/main/java/com/zhiyun/zhiyun03/directory/servcie/impl/DirectoryServiceImpl.java
new file mode 100644
index 0000000..e10e1ff
--- /dev/null
+++ b/src/main/java/com/zhiyun/zhiyun03/directory/servcie/impl/DirectoryServiceImpl.java
@@ -0,0 +1,19 @@
+package com.zhiyun.zhiyun03.directory.servcie.impl;
+
+import com.zhiyun.zhiyun03.course.dao.DirectoryDAO;
+import com.zhiyun.zhiyun03.directory.entity.Directory;
+import com.zhiyun.zhiyun03.directory.servcie.DirectoryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DirectoryServiceImpl implements DirectoryService {
+
+ @Autowired
+ private DirectoryDAO directoryDAO;
+
+ @Override
+ public void addDirectory(Directory directory) {
+ directoryDAO.insert(directory);
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 0653c9e..27bac68 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -12,9 +12,12 @@ mybatis:
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
- driverClassName: com.mysql.jdbc.Driver
+ driverClassName: com.mysql.cj.jdbc.Driver
druid:
url: jdbc:mysql://localhost:3306/zhiyun?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
- password: 123456
+ password: root
+
+swagger:
+ enabled: true
\ No newline at end of file
diff --git a/src/main/resources/mapper/directory/DirectoryDAO.xml b/src/main/resources/mapper/directory/DirectoryDAO.xml
new file mode 100644
index 0000000..50e1e0e
--- /dev/null
+++ b/src/main/resources/mapper/directory/DirectoryDAO.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+ id, dir_name, dir_img
+
+
+
+ delete from directory
+ where id = #{id,jdbcType=INTEGER}
+
+
+ insert into directory (id,dir_name, dir_img)
+ values (#{id},#{dirName,jdbcType=VARCHAR}, #{dirImg,jdbcType=VARCHAR})
+
+
+ insert into directory
+
+
+ dir_name,
+
+
+ dir_img,
+
+
+
+
+ #{dirName,jdbcType=VARCHAR},
+
+
+ #{dirImg,jdbcType=VARCHAR},
+
+
+
+
+ update directory
+
+
+ dir_name = #{dirName,jdbcType=VARCHAR},
+
+
+ dir_img = #{dirImg,jdbcType=VARCHAR},
+
+
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update directory
+ set dir_name = #{dirName,jdbcType=VARCHAR},
+ dir_img = #{dirImg,jdbcType=VARCHAR}
+ where id = #{id,jdbcType=INTEGER}
+
+
\ No newline at end of file