diff --git a/springboot/src/main/java/com/example/controller/CourseController.java b/springboot/src/main/java/com/example/controller/CourseController.java index 96fc022..de5e84e 100644 --- a/springboot/src/main/java/com/example/controller/CourseController.java +++ b/springboot/src/main/java/com/example/controller/CourseController.java @@ -4,10 +4,7 @@ import com.example.common.Result; import com.example.entity.Course; import com.example.service.CourseService; import com.github.pagehelper.PageInfo; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -17,12 +14,39 @@ public class CourseController { @Resource private CourseService courseService; - - @GetMapping("/selectPage") + /** + * 分页条件查询课程 + */ + @GetMapping("/selectPage") public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, Course course){ PageInfo pageInfo = courseService.selectPage(pageNum, pageSize,course); return Result.success(pageInfo); } + /** + * 新增课程 + */ + @PostMapping("/add") + public Result add(@RequestBody Course course){ + courseService.add(course); + return Result.success(); + } + /** + * 更新课程 + */ + @PutMapping("/update") + public Result update(@RequestBody Course course){ + courseService.updateById(course); + return Result.success(); + } + + /** + * 删除课程 + */ + @DeleteMapping("/delete/{id}") + public Result delete(@PathVariable Integer id){ + courseService.deleteById(id); + return Result.success(); + } } diff --git a/springboot/src/main/java/com/example/mapper/CourseMapper.java b/springboot/src/main/java/com/example/mapper/CourseMapper.java index 747d961..c856804 100644 --- a/springboot/src/main/java/com/example/mapper/CourseMapper.java +++ b/springboot/src/main/java/com/example/mapper/CourseMapper.java @@ -1,11 +1,21 @@ package com.example.mapper; import com.example.entity.Course; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; public interface CourseMapper { @Select("select * from course where name like concat('%',#{name},'%') and no like concat('%',#{no},'%') and teacher like concat('%',#{teacher},'%') order by id desc") List selectAll(Course course); + @Insert("insert into course (name, no, descr, times, teacher) values(#{name},#{no},#{descr},#{times},#{teacher})") + void insert(Course course); + @Update("update course set name=#{name},no=#{no},descr=#{descr},times=#{times},teacher=#{teacher} where id=#{id}") + void updateById(Course course); + + @Delete("delete from course where id=#{id}") + void deleteById(Integer id); } diff --git a/springboot/src/main/java/com/example/service/CourseService.java b/springboot/src/main/java/com/example/service/CourseService.java index 65b3425..fdd3b7e 100644 --- a/springboot/src/main/java/com/example/service/CourseService.java +++ b/springboot/src/main/java/com/example/service/CourseService.java @@ -21,4 +21,16 @@ public class CourseService { List coursesList = courseMapper.selectAll(course); return PageInfo.of(coursesList); } + //新增数据 + public void add(Course course) { + courseMapper.insert(course); + } + + public void updateById(Course course) { + courseMapper.updateById(course); + } + + public void deleteById(Integer id) { + courseMapper.deleteById(id); + } } diff --git a/springboot/target/classes/com/example/controller/CourseController.class b/springboot/target/classes/com/example/controller/CourseController.class index 94503c7..d9ebb0c 100644 Binary files a/springboot/target/classes/com/example/controller/CourseController.class and b/springboot/target/classes/com/example/controller/CourseController.class differ diff --git a/springboot/target/classes/com/example/mapper/CourseMapper.class b/springboot/target/classes/com/example/mapper/CourseMapper.class index 22cafae..823ca9c 100644 Binary files a/springboot/target/classes/com/example/mapper/CourseMapper.class and b/springboot/target/classes/com/example/mapper/CourseMapper.class differ diff --git a/springboot/target/classes/com/example/service/CourseService.class b/springboot/target/classes/com/example/service/CourseService.class index 039fad0..3548b73 100644 Binary files a/springboot/target/classes/com/example/service/CourseService.class and b/springboot/target/classes/com/example/service/CourseService.class differ diff --git a/vue/src/views/manager/Course.vue b/vue/src/views/manager/Course.vue index d754e77..6d612d2 100644 --- a/vue/src/views/manager/Course.vue +++ b/vue/src/views/manager/Course.vue @@ -8,7 +8,7 @@
- 新 增 + 新 增
@@ -20,8 +20,8 @@ @@ -31,12 +31,39 @@ @current-change = "handleCurrentChange" background layout="prev, pager, next" :total="data.total" />
+ + + + + + + + + + + + + + + + + + + / + +
\ No newline at end of file