dyc
parent
e15847538c
commit
2d5ca1f2a8
@ -0,0 +1,48 @@
|
||||
package com.zhiyun.zhiyun03.course.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JsonResult<T> {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private T data;
|
||||
private Long count;
|
||||
|
||||
public static JsonResult ok() {
|
||||
|
||||
JsonResult jsonResult = new JsonResult();
|
||||
jsonResult.setCode(200);//code值是自行定义
|
||||
jsonResult.setMsg("success");
|
||||
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
public static <T> 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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<Course> courseList = courseService.selectAll();
|
||||
|
||||
PageInfo<Course> 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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<Course> selectAll();
|
||||
}
|
@ -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<Course> selectAll() {
|
||||
return courseDAO.selectAll();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.zhiyun.zhiyun03.directory.servcie;
|
||||
|
||||
import com.zhiyun.zhiyun03.directory.entity.Directory;
|
||||
|
||||
public interface DirectoryService {
|
||||
void addDirectory(Directory directory);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhiyun.zhiyun03.course.dao.DirectoryDAO">
|
||||
<resultMap id="BaseResultMap" type="com.zhiyun.zhiyun03.directory.entity.Directory">
|
||||
<id column="id" jdbcType="INTEGER" property="id" />
|
||||
<result column="dir_name" jdbcType="VARCHAR" property="dirName" />
|
||||
<result column="dir_img" jdbcType="VARCHAR" property="dirImg" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, dir_name, dir_img
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from directory
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from directory
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.zhiyun.zhiyun03.directory.entity.Directory" useGeneratedKeys="true">
|
||||
insert into directory (id,dir_name, dir_img)
|
||||
values (#{id},#{dirName,jdbcType=VARCHAR}, #{dirImg,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.zhiyun.zhiyun03.directory.entity.Directory" useGeneratedKeys="true">
|
||||
insert into directory
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="dirName != null">
|
||||
dir_name,
|
||||
</if>
|
||||
<if test="dirImg != null">
|
||||
dir_img,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="dirName != null">
|
||||
#{dirName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="dirImg != null">
|
||||
#{dirImg,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.zhiyun.zhiyun03.directory.entity.Directory">
|
||||
update directory
|
||||
<set>
|
||||
<if test="dirName != null">
|
||||
dir_name = #{dirName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="dirImg != null">
|
||||
dir_img = #{dirImg,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.zhiyun.zhiyun03.directory.entity.Directory">
|
||||
update directory
|
||||
set dir_name = #{dirName,jdbcType=VARCHAR},
|
||||
dir_img = #{dirImg,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
Loading…
Reference in New Issue