From 403cc1127b84f90b58ec59a033c86648307b99ea Mon Sep 17 00:00:00 2001 From: 19076 <1907647072@qq.com> Date: Tue, 9 Aug 2022 19:42:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=87=E7=AB=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course/controller/api/NewsController.java | 65 +++++++++++++++---- .../course/mapper/database/NewsMapper.java | 23 +++++-- .../course/service/api/INewsService.java | 29 +++++++-- .../service/api/impl/NewsServiceImpl.java | 44 +++++++++---- .../resources/mybatis/mapper/NewsMapper.xml | 43 +++++++++--- 5 files changed, 162 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/snhanyue/course/controller/api/NewsController.java b/src/main/java/com/snhanyue/course/controller/api/NewsController.java index acd4c5d..eff00cb 100644 --- a/src/main/java/com/snhanyue/course/controller/api/NewsController.java +++ b/src/main/java/com/snhanyue/course/controller/api/NewsController.java @@ -1,6 +1,8 @@ package com.snhanyue.course.controller.api; import com.snhanyue.course.dto.NewsDTO; +import com.snhanyue.course.emum.State; +import com.snhanyue.course.exception.ServiceException; import com.snhanyue.course.service.api.INewsService; import com.snhanyue.course.util.json.JsonResult; import com.snhanyue.course.vo.NewsVO; @@ -15,28 +17,63 @@ public class NewsController { @Autowired INewsService iNewsService; + /** + * 添加信息 + * + * @param newsDTO + * @return + */ @PostMapping("/News/addNews") - public JsonResult addNews(@Validated NewsDTO newsDTO){ + public JsonResult addNews(@Validated NewsDTO newsDTO) { iNewsService.addNews(newsDTO); - return JsonResult.ok(); + return JsonResult.ok("添加文章信息成功"); } - @PostMapping("/News/DeleteNews") - public JsonResult deleteNews(int id){ - iNewsService.deleteNews(id); - return JsonResult.ok("已成功删除"+id); + /** + * 删除id对应信息 + * + * @param id + * @return + */ + @PostMapping("/News/DeleteNewsById") + public JsonResult deleteNews(int id) { + int i = iNewsService.deleteNewsById(id); + if (i > 0) { + return JsonResult.ok(); + } else { + return JsonResult.fail(State.ERR_USER_NAME_DOES_NOT_EXIST, id + "对应作者名不存在"); + } } - @PostMapping("/News/UpdateNews") - public JsonResult updateNews(int id,String title){ - - int i = iNewsService.updateNews(id, title); - return JsonResult.ok("修改完成"+i+"处"); + /** + * 更改id对应文章标题 + * + * @param id + * @param title + * @return + */ + @PostMapping("/News/UpdateNewsById") + public JsonResult updateNews(int id, String title) { + int i = 0; + if (id != 0 || title.isEmpty()) { + i = iNewsService.updateNewsById(id, title); + } + if (i == 1) { + return JsonResult.ok(title+"更改已完成"); + } else { + throw new ServiceException(State.ERR_CATEGORY_NAME_DUPLICATE, "系统异常或用户名已存在"); + } } - @GetMapping("/News/SelectNews") - public NewsVO selectNews(String title){ - return iNewsService.selectNews(title); + /** + * 获取标题对应信息 + * + * @param title + * @return + */ + @GetMapping("/News/GetNewsByTitle") + public NewsVO selectNews(String title) { + return iNewsService.getNewsByTitle(title); } diff --git a/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java b/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java index 77d9c5a..a6b7c34 100644 --- a/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java +++ b/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java @@ -15,10 +15,25 @@ public interface NewsMapper { */ int insertNews(News news); - NewsVO selectNewsAuthor(String author); - - int deleteByTitleInt(int id); + /** + *删除id对应数据 + * @param id + * @return + */ + int deleteByNewsId(int id); - int updateNews(@Param("id")int id,@Param("title")String title); + /** + *更改id对应标题 + * @param id + * @param title + * @return + */ + int updateNewsTitle(@Param("id")int id,@Param("title")String title); + /** + *获取id对应标题 + * @param Title + * @return + */ + NewsVO getBayNewsTitle(String Title); } diff --git a/src/main/java/com/snhanyue/course/service/api/INewsService.java b/src/main/java/com/snhanyue/course/service/api/INewsService.java index 7e97b4c..9daf97a 100644 --- a/src/main/java/com/snhanyue/course/service/api/INewsService.java +++ b/src/main/java/com/snhanyue/course/service/api/INewsService.java @@ -4,12 +4,33 @@ import com.snhanyue.course.dto.NewsDTO; import com.snhanyue.course.vo.NewsVO; public interface INewsService { - void addNews(NewsDTO newsDTO); + /** + * 给Dto插入获取的数据 + * @param newsDTO + */ + int addNews(NewsDTO newsDTO); - int deleteNews(int id); + /** + * 删除id对应信息 + * @param id + * @return + */ + int deleteNewsById(int id); - int updateNews(int id,String title); + /** + * 更新id对应标题 + * @param id + * @param title + * @return + */ + int updateNewsById(int id, String title); + + /** + * 获取标题 + * @param title + * @return + */ + NewsVO getNewsByTitle(String title); - NewsVO selectNews(String title); } diff --git a/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java b/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java index 3fb5e45..55ac95b 100644 --- a/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java +++ b/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java @@ -12,19 +12,22 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service - public class NewsServiceImpl implements INewsService { @Autowired NewsMapper newsMapper; - //取出文章作者名 + /** + * 给DTO添加信息 + * @param newsDTO + * @return + */ @Override - public void addNews(NewsDTO newsDTO) { - //获取用户输入的名字 - String author = newsDTO.getAuthor(); + public int addNews(NewsDTO newsDTO) { + //获取标题名 + String title = newsDTO.getTitle(); //从数据库进行比对 - NewsVO newsVO = newsMapper.selectNewsAuthor(author); + NewsVO newsVO = newsMapper.getBayNewsTitle(title); if (newsVO!=null){ throw new ServiceException(State.ERR_CATEGORY_NAME_DUPLICATE,"用户名已存在"); } @@ -35,21 +38,38 @@ public class NewsServiceImpl implements INewsService { if (i!=1){ throw new ServiceException(State.ERR_INSERT,"插入数据错误请稍后重试"); } + return 1; } + /** + * 删除id对应信息 + * @param id + * @return + */ @Override - public int deleteNews(int id) { - return newsMapper.deleteByTitleInt(id); + public int deleteNewsById(int id) { + return newsMapper.deleteByNewsId(id); } + /** + * 更新id对应标题 + * @param id + * @param title + * @return + */ @Override - public int updateNews(int id, String title) { - return newsMapper.updateNews(id, title); + public int updateNewsById(int id, String title) { + return newsMapper.updateNewsTitle(id, title); } + /** + * 获取标题对应信息 + * @param title + * @return + */ @Override - public NewsVO selectNews(String title) { - return newsMapper.selectNewsAuthor(title); + public NewsVO getNewsByTitle(String title) { + return newsMapper.getBayNewsTitle(title); } } diff --git a/src/main/resources/mybatis/mapper/NewsMapper.xml b/src/main/resources/mybatis/mapper/NewsMapper.xml index 838dca4..a7c510b 100644 --- a/src/main/resources/mybatis/mapper/NewsMapper.xml +++ b/src/main/resources/mybatis/mapper/NewsMapper.xml @@ -31,19 +31,46 @@ #{releaseTime}, #{forwardingNumber}) - - update news set title = #{title} where id = #{id} - - - delete from news where id=#{id} + + + delete + from news + where id = #{id} - + select + + from news + where title = #{title} - + + + id, + title, + create_time, + alter_time, + is_enable, + click_times, + update_status, + admin_id, + summary_article, + author, + article_body, + release_time, + forwarding_number + + + + -- Gitee From d7222266b074610f9998551092ba820c4034b682 Mon Sep 17 00:00:00 2001 From: 19076 <1907647072@qq.com> Date: Thu, 11 Aug 2022 13:06:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E7=AB=A03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/CourseController.java | 78 +++++++++++++++++++ .../course/controller/api/NewsController.java | 53 ++++++------- .../com/snhanyue/course/dto/CourseDTO.java | 17 ++++ .../com/snhanyue/course/entity/Course.java | 17 ++++ .../java/com/snhanyue/course/entity/News.java | 4 + .../course/mapper/database/CourseMapper.java | 46 +++++++++++ .../course/mapper/database/NewsMapper.java | 8 ++ .../course/service/api/ICourseService.java | 39 ++++++++++ .../course/service/api/INewsService.java | 7 +- .../service/api/impl/CourseServiceImpl.java | 73 +++++++++++++++++ .../service/api/impl/NewsServiceImpl.java | 24 ++---- .../java/com/snhanyue/course/vo/CourseVO.java | 17 ++++ .../resources/mybatis/mapper/CourseMapper.xml | 64 +++++++++++++++ .../resources/mybatis/mapper/NewsMapper.xml | 6 ++ 14 files changed, 404 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/snhanyue/course/controller/api/CourseController.java create mode 100644 src/main/java/com/snhanyue/course/dto/CourseDTO.java create mode 100644 src/main/java/com/snhanyue/course/entity/Course.java create mode 100644 src/main/java/com/snhanyue/course/mapper/database/CourseMapper.java create mode 100644 src/main/java/com/snhanyue/course/service/api/ICourseService.java create mode 100644 src/main/java/com/snhanyue/course/service/api/impl/CourseServiceImpl.java create mode 100644 src/main/java/com/snhanyue/course/vo/CourseVO.java create mode 100644 src/main/resources/mybatis/mapper/CourseMapper.xml diff --git a/src/main/java/com/snhanyue/course/controller/api/CourseController.java b/src/main/java/com/snhanyue/course/controller/api/CourseController.java new file mode 100644 index 0000000..6d28377 --- /dev/null +++ b/src/main/java/com/snhanyue/course/controller/api/CourseController.java @@ -0,0 +1,78 @@ +package com.snhanyue.course.controller.api; + +import com.snhanyue.course.dto.CourseDTO; +import com.snhanyue.course.emum.State; +import com.snhanyue.course.service.api.ICourseService; +import com.snhanyue.course.util.json.JsonResult; +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; + +@RestController +@RequestMapping(value = "/api") +public class CourseController { + + @Autowired + ICourseService courseService; + + /** + * 插入课程信息 + * @param courseDTO + * @return + */ + @PostMapping("AddCourse") + public JsonResult AddCourse(CourseDTO courseDTO){ + int i = courseService.AddCourse(courseDTO); + if (i!=1){ + return JsonResult.fail(State.ERR_INSERT,"插入失败请稍后重试"); + } + return JsonResult.ok(); + } + + /** + * 删除id对应课程信息 + * @param id + * @return + */ + @PostMapping("DeleteCourse") + public JsonResult DeleteCourse(Integer id){ + int i = courseService.DeleteCourse(id); + if (i!=1){ + return JsonResult.fail(State.ERR_USER_NAME_DOES_NOT_EXIST,"删除失败请稍后重试"); + } + return JsonResult.ok(); + } + + /** + * 更新id对应课程信息 + * @param id + * @param course + * @return + */ + @PostMapping("UpdateCourse") + public JsonResult UpdateCourse(Integer id, String course){ + int i = 0; + if (id!=0||!course.isEmpty()) { + i = courseService.UpdateCourse(id, course); + } + if (i!=1||course.isEmpty()){ + return JsonResult.fail(State.ERR_CATEGORY_NAME_DUPLICATE,"更新失败请稍后重试"); + } + return JsonResult.ok(); + } + + /** + * 查询id对应课程信息 + * @param id + * @return + */ + @PostMapping("SelectCourse") + public Object SelectCourse(Integer id){ + if (id==0||id!=courseService.SelectCourse(id).getId()){ + return JsonResult.fail(State.ERR_UNKNOWN_ERROR,"查询出错或id不存在请稍后重试"); + } + return courseService.SelectCourse(id); + } + +} diff --git a/src/main/java/com/snhanyue/course/controller/api/NewsController.java b/src/main/java/com/snhanyue/course/controller/api/NewsController.java index eff00cb..0251bc5 100644 --- a/src/main/java/com/snhanyue/course/controller/api/NewsController.java +++ b/src/main/java/com/snhanyue/course/controller/api/NewsController.java @@ -2,7 +2,6 @@ package com.snhanyue.course.controller.api; import com.snhanyue.course.dto.NewsDTO; import com.snhanyue.course.emum.State; -import com.snhanyue.course.exception.ServiceException; import com.snhanyue.course.service.api.INewsService; import com.snhanyue.course.util.json.JsonResult; import com.snhanyue.course.vo.NewsVO; @@ -20,59 +19,55 @@ public class NewsController { /** * 添加信息 * - * @param newsDTO - * @return */ @PostMapping("/News/addNews") - public JsonResult addNews(@Validated NewsDTO newsDTO) { - iNewsService.addNews(newsDTO); - return JsonResult.ok("添加文章信息成功"); + public JsonResult addNews(@Validated NewsDTO newsDTO) { + int result = iNewsService.addNews(newsDTO); + if (result != 1) { + return JsonResult.fail(State.ERR_INSERT, "添加失败!请稍后重试"); + } + return JsonResult.ok(); + } /** - * 删除id对应信息 + * 删除id对应文章信息 * - * @param id - * @return */ @PostMapping("/News/DeleteNewsById") public JsonResult deleteNews(int id) { - int i = iNewsService.deleteNewsById(id); - if (i > 0) { - return JsonResult.ok(); + int ids = new NewsVO().getId(); + if (id == 0 || id != ids) { + return JsonResult.fail(State.ERR_USER_NAME_DOES_NOT_EXIST, id + "作者id不存在"); } else { - return JsonResult.fail(State.ERR_USER_NAME_DOES_NOT_EXIST, id + "对应作者名不存在"); + iNewsService.deleteNewsById(id); + return JsonResult.ok(); } } /** * 更改id对应文章标题 * - * @param id - * @param title - * @return */ @PostMapping("/News/UpdateNewsById") - public JsonResult updateNews(int id, String title) { - int i = 0; - if (id != 0 || title.isEmpty()) { - i = iNewsService.updateNewsById(id, title); - } - if (i == 1) { - return JsonResult.ok(title+"更改已完成"); - } else { - throw new ServiceException(State.ERR_CATEGORY_NAME_DUPLICATE, "系统异常或用户名已存在"); + public JsonResult updateNews(int id, String title) { + if (id == 0 || title.isEmpty()) { + return JsonResult.fail(State.ERR_UPDATE, "id或标题不存在"); } + iNewsService.updateNewsById(id, title); + return JsonResult.ok(); + } /** - * 获取标题对应信息 + * 获取标题对应文章信息 * - * @param title - * @return */ @GetMapping("/News/GetNewsByTitle") - public NewsVO selectNews(String title) { + public Object selectNews(String title) { + if (title.isEmpty() || !title.equals(iNewsService.getNewsByTitle(title).getTitle())) { + return JsonResult.fail(State.ERR_UNKNOWN_ERROR, "查询出错或标题不存在"); + } return iNewsService.getNewsByTitle(title); } diff --git a/src/main/java/com/snhanyue/course/dto/CourseDTO.java b/src/main/java/com/snhanyue/course/dto/CourseDTO.java new file mode 100644 index 0000000..758c7a4 --- /dev/null +++ b/src/main/java/com/snhanyue/course/dto/CourseDTO.java @@ -0,0 +1,17 @@ +package com.snhanyue.course.dto; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class CourseDTO implements Serializable { + private int id; + private int isEnable; + private String course; + private String startTime; + private String updateTime; + private String endTime; + private int studentId; + private int teacherId; +} diff --git a/src/main/java/com/snhanyue/course/entity/Course.java b/src/main/java/com/snhanyue/course/entity/Course.java new file mode 100644 index 0000000..8c681d7 --- /dev/null +++ b/src/main/java/com/snhanyue/course/entity/Course.java @@ -0,0 +1,17 @@ +package com.snhanyue.course.entity; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class Course implements Serializable { + private int id; + private int isEnable; + private String course; + private String startTime; + private String updateTime; + private String endTime; + private int studentId; + private int teacherId; +} diff --git a/src/main/java/com/snhanyue/course/entity/News.java b/src/main/java/com/snhanyue/course/entity/News.java index 0470f16..b108dcc 100644 --- a/src/main/java/com/snhanyue/course/entity/News.java +++ b/src/main/java/com/snhanyue/course/entity/News.java @@ -2,11 +2,15 @@ package com.snhanyue.course.entity; import lombok.Data; +import javax.validation.constraints.NotNull; import java.io.Serializable; @Data public class News implements Serializable { + + @NotNull private int id; + private String title; private String createTime; private String alterTime; diff --git a/src/main/java/com/snhanyue/course/mapper/database/CourseMapper.java b/src/main/java/com/snhanyue/course/mapper/database/CourseMapper.java new file mode 100644 index 0000000..c0e6750 --- /dev/null +++ b/src/main/java/com/snhanyue/course/mapper/database/CourseMapper.java @@ -0,0 +1,46 @@ +package com.snhanyue.course.mapper.database; + +import com.snhanyue.course.dto.CourseDTO; +import com.snhanyue.course.vo.CourseVO; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface CourseMapper { + + /** + * 添加课程信息 + * @param courseDTO + * @return + */ + int AddCourse(CourseDTO courseDTO); + + /** + * 删除课程信息 + * @param id + * @return + */ + int DeleteCourse(Integer id); + + /** + * 根据id更改课程信息 + * @param id + * @return + */ + int UpdateCourse(@Param("id") Integer id,@Param("course") String course); + + /** + * 根据id查询课程新息 + * @param id + * @return + */ + CourseVO SelectCourse(Integer id); + + /** + * 查询课程名 + * @param course + * @return + */ + String SelectCourseByCourse(String course); + +} diff --git a/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java b/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java index a6b7c34..b2e241f 100644 --- a/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java +++ b/src/main/java/com/snhanyue/course/mapper/database/NewsMapper.java @@ -36,4 +36,12 @@ public interface NewsMapper { * @return */ NewsVO getBayNewsTitle(String Title); + + /** + * 根据id查询 + * @param id + * @return + */ + NewsVO getNewsById(Integer id); + } diff --git a/src/main/java/com/snhanyue/course/service/api/ICourseService.java b/src/main/java/com/snhanyue/course/service/api/ICourseService.java new file mode 100644 index 0000000..c1b0442 --- /dev/null +++ b/src/main/java/com/snhanyue/course/service/api/ICourseService.java @@ -0,0 +1,39 @@ +package com.snhanyue.course.service.api; + +import com.snhanyue.course.dto.CourseDTO; +import com.snhanyue.course.vo.CourseVO; + +public interface ICourseService { + + /** + * 插入课程信息 + * @param courseDTO + * @return + */ + int AddCourse(CourseDTO courseDTO); + + /** + * 根据id删除课程信息 + * @param id + * @return + */ + int DeleteCourse(Integer id); + + /** + * 根据id更改课程信息 + * @param id + * @param course + * @return + */ + int UpdateCourse(Integer id,String course); + + /** + * 根据id查询课程信息 + * @param id + * @return + */ + CourseVO SelectCourse(Integer id); + + + +} diff --git a/src/main/java/com/snhanyue/course/service/api/INewsService.java b/src/main/java/com/snhanyue/course/service/api/INewsService.java index 9daf97a..e4751c8 100644 --- a/src/main/java/com/snhanyue/course/service/api/INewsService.java +++ b/src/main/java/com/snhanyue/course/service/api/INewsService.java @@ -13,17 +13,15 @@ public interface INewsService { /** * 删除id对应信息 * @param id - * @return */ - int deleteNewsById(int id); + void deleteNewsById(int id); /** * 更新id对应标题 * @param id * @param title - * @return */ - int updateNewsById(int id, String title); + void updateNewsById(int id, String title); /** * 获取标题 @@ -33,4 +31,5 @@ public interface INewsService { NewsVO getNewsByTitle(String title); + } diff --git a/src/main/java/com/snhanyue/course/service/api/impl/CourseServiceImpl.java b/src/main/java/com/snhanyue/course/service/api/impl/CourseServiceImpl.java new file mode 100644 index 0000000..b48269c --- /dev/null +++ b/src/main/java/com/snhanyue/course/service/api/impl/CourseServiceImpl.java @@ -0,0 +1,73 @@ +package com.snhanyue.course.service.api.impl; + +import com.snhanyue.course.dto.CourseDTO; +import com.snhanyue.course.mapper.database.CourseMapper; +import com.snhanyue.course.service.api.ICourseService; +import com.snhanyue.course.vo.CourseVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class CourseServiceImpl implements ICourseService { + + @Autowired + CourseMapper courseMapper; + + /** + * 插入课程信息 + * @param courseDTO + * @return + */ + @Override + public int AddCourse(CourseDTO courseDTO) { + int i = courseMapper.AddCourse(courseDTO); + CourseVO courseVO = new CourseVO(); + String course = courseMapper.SelectCourseByCourse(courseVO.getCourse()); + String courseD = courseDTO.getCourse(); + if (i != 0||course.equals(courseD)) { + return 1; + } + return 0; + } + + /** + * 删除id对应课程信息 + * @param id + * @return + */ + @Override + public int DeleteCourse(Integer id) { + int i = courseMapper.DeleteCourse(id); + if (i!=0){ + return 1; + } + return 0; + + } + + /** + * 更新id对应课程信息 + * @param id + * @param course + * @return + */ + @Override + public int UpdateCourse(Integer id, String course) { + int i = courseMapper.UpdateCourse(id,course); + if (i!=0){ + return 1; + } + return 0; + + } + + /** + * 根据id查询课程信息 + * @param id + * @return + */ + @Override + public CourseVO SelectCourse(Integer id) { + return courseMapper.SelectCourse(id); + } +} diff --git a/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java b/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java index 55ac95b..58c0b68 100644 --- a/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java +++ b/src/main/java/com/snhanyue/course/service/api/impl/NewsServiceImpl.java @@ -19,21 +19,16 @@ public class NewsServiceImpl implements INewsService { /** * 给DTO添加信息 - * @param newsDTO - * @return */ @Override public int addNews(NewsDTO newsDTO) { - //获取标题名 String title = newsDTO.getTitle(); - //从数据库进行比对 NewsVO newsVO = newsMapper.getBayNewsTitle(title); if (newsVO!=null){ throw new ServiceException(State.ERR_CATEGORY_NAME_DUPLICATE,"用户名已存在"); } News news = new News(); BeanUtils.copyProperties(newsDTO,news); - // 补全状态 int i = newsMapper.insertNews(news); if (i!=1){ throw new ServiceException(State.ERR_INSERT,"插入数据错误请稍后重试"); @@ -43,29 +38,26 @@ public class NewsServiceImpl implements INewsService { /** * 删除id对应信息 - * @param id - * @return */ @Override - public int deleteNewsById(int id) { - return newsMapper.deleteByNewsId(id); + public void deleteNewsById(int id) { + if (id!=0||id==newsMapper.getNewsById(id).getId()) { + newsMapper.deleteByNewsId(id); + } } /** * 更新id对应标题 - * @param id - * @param title - * @return */ @Override - public int updateNewsById(int id, String title) { - return newsMapper.updateNewsTitle(id, title); + public void updateNewsById(int id, String title) { + if (id!=0||!title.isEmpty()){ + newsMapper.updateNewsTitle(id, title); + } } /** * 获取标题对应信息 - * @param title - * @return */ @Override public NewsVO getNewsByTitle(String title) { diff --git a/src/main/java/com/snhanyue/course/vo/CourseVO.java b/src/main/java/com/snhanyue/course/vo/CourseVO.java new file mode 100644 index 0000000..b182440 --- /dev/null +++ b/src/main/java/com/snhanyue/course/vo/CourseVO.java @@ -0,0 +1,17 @@ +package com.snhanyue.course.vo; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class CourseVO implements Serializable { + private int id; + private int isEnable; + private String course; + private String startTime; + private String updateTime; + private String endTime; + private int studentId; + private int teacherId; +} diff --git a/src/main/resources/mybatis/mapper/CourseMapper.xml b/src/main/resources/mybatis/mapper/CourseMapper.xml new file mode 100644 index 0000000..f110468 --- /dev/null +++ b/src/main/resources/mybatis/mapper/CourseMapper.xml @@ -0,0 +1,64 @@ + + + + + + + insert into course(id, + is_enable, + course, + start_time, + update_time, + end_time, + student_id, + teacher_id) + values (#{id}, + #{isEnable}, + #{course}, + #{startTime}, + #{updateTime}, + #{endTime}, + #{studentId}, + #{teacherId}) + + + update course + set course=#{course} + where id = #{id} + + + delete + from course + where id = #{id} + + + + + + id, + is_enable, + course, + start_time, + update_time, + end_time, + student_id, + teacher_id + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/NewsMapper.xml b/src/main/resources/mybatis/mapper/NewsMapper.xml index a7c510b..d67027e 100644 --- a/src/main/resources/mybatis/mapper/NewsMapper.xml +++ b/src/main/resources/mybatis/mapper/NewsMapper.xml @@ -51,6 +51,12 @@ from news where title = #{title} + -- Gitee