diff --git a/src/main/java/com/letoy/study/dao/CourseMapper.java b/src/main/java/com/letoy/study/dao/CourseMapper.java index 1ff8023e1fdf841b1bf4d8cd4d44b6ad9ceca1e6..65594a7f9a38455a9b5e8abccb10b97174337097 100644 --- a/src/main/java/com/letoy/study/dao/CourseMapper.java +++ b/src/main/java/com/letoy/study/dao/CourseMapper.java @@ -1,12 +1,18 @@ package com.letoy.study.dao; import com.letoy.study.entity.CourseInfo; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Component; + +import java.util.List; /** * @program:letoy-study-java * @author: WeiHaoL * @Time: 2021/1/23 下午12:25 */ +@Mapper +@Component public interface CourseMapper { @@ -17,10 +23,10 @@ public interface CourseMapper { int deleteCourse(CourseInfo courseInfo); // 获取全部课程信息 - CourseInfo findAllCourseInfo(); + List findAllCourseInfo(); // 获取全部课程信息根据类型信息过滤 - CourseInfo findAllCourseInfoByCourseType(String courseType); + List findAllCourseInfoByCourseType(String courseType); } diff --git a/src/main/java/com/letoy/study/entity/CourseInfo.java b/src/main/java/com/letoy/study/entity/CourseInfo.java index 65699c8c19c3b1819cc540ea4f0a60e388617583..43f000693f00f3d083fe0a8942b535d1f8951420 100644 --- a/src/main/java/com/letoy/study/entity/CourseInfo.java +++ b/src/main/java/com/letoy/study/entity/CourseInfo.java @@ -6,6 +6,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.sql.Timestamp; + @Data @AllArgsConstructor @NoArgsConstructor @@ -17,13 +19,88 @@ public class CourseInfo { private String courseName; @ApiModelProperty(value = "课程类型", example = "后端课程", dataType = "String") private String courseType; + @ApiModelProperty(value = "课程视频地址", example = "", dataType = "String") private String courseVideoUrl; + @ApiModelProperty(value = "课程描述", example = "java入门", dataType = "String") private String courseDescribe; + @ApiModelProperty(value = "课程浏览量", example = "200", dataType = "String") private String courseViews; + @ApiModelProperty(value = "课程作者ID", example = "1", dataType = "long") private long userId; + @ApiModelProperty(value = "课程评论集编号", example = "1", dataType = "long") private long courseCommentId; + @ApiModelProperty(value = "课程发布时间", example = "", dataType = "java.sql.Timestamp") private java.sql.Timestamp coursePublishTime; + public long getCourseId() { + return courseId; + } + + public void setCourseId(long courseId) { + this.courseId = courseId; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getCourseType() { + return courseType; + } + + public void setCourseType(String courseType) { + this.courseType = courseType; + } + + public String getCourseVideoUrl() { + return courseVideoUrl; + } + + public void setCourseVideoUrl(String courseVideoUrl) { + this.courseVideoUrl = courseVideoUrl; + } + + public String getCourseDescribe() { + return courseDescribe; + } + + public void setCourseDescribe(String courseDescribe) { + this.courseDescribe = courseDescribe; + } + + public String getCourseViews() { + return courseViews; + } + + public void setCourseViews(String courseViews) { + this.courseViews = courseViews; + } + + public long getUserId() { + return userId; + } + + public void setUserId(long userId) { + this.userId = userId; + } + + public long getCourseCommentId() { + return courseCommentId; + } + + public void setCourseCommentId(long courseCommentId) { + this.courseCommentId = courseCommentId; + } + public Timestamp getCoursePublishTime() { + return coursePublishTime; + } + public void setCoursePublishTime(Timestamp coursePublishTime) { + this.coursePublishTime = coursePublishTime; + } } diff --git a/src/main/resources/mapper/CourseMapper.xml b/src/main/resources/mapper/CourseMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef6bae094528b5d47dc7d436ad598c15d3ed5d39 --- /dev/null +++ b/src/main/resources/mapper/CourseMapper.xml @@ -0,0 +1,63 @@ + + + + + + + insert into course_info ( + course_id, course_name, course_type, + course_video_url,course_describe, + course_views,user_id,course_comment_id,course_publish_time, + ) + VALUES ( + #{courseId}, #{courseName}, #{courseType}, + #{courseVideoUrl},#{courseDescribe}, + #{courseViews},#{userId},#{courseCommentId},#{coursePublishTime}, + ) + + + + + delete from course_info + where course_id =#{courseId} + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/letoy/study/dao/CourseMapperTest.java b/src/test/java/com/letoy/study/dao/CourseMapperTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e174a60fb1f3939c702d49db76c9540082026b72 --- /dev/null +++ b/src/test/java/com/letoy/study/dao/CourseMapperTest.java @@ -0,0 +1,134 @@ +package com.letoy.study.dao; + +import com.letoy.study.entity.CourseInfo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +import java.sql.Timestamp; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.*; +@SpringBootTest +@RunWith(SpringRunner.class) +public class CourseMapperTest { + /** + * @program:letoy-study-java + * @author: Yueyang Ren + * @Time: 2021/1/24 下午15:32 + * @return 测试CourseMapper接口的方法 + */ + @Resource + CourseMapper courseMapper; + @Test + public void releaseCourse() { + CourseInfo course1 = new CourseInfo(); + course1.setCourseId(2); + course1.setCourseName("spring基础"); + course1.setCourseType("后端基础类型"); + course1.setCourseVideoUrl("192.6.1"); + course1.setCourseDescribe("spring入门"); + course1.setCourseViews("300"); + course1.setUserId(2); + course1.setCourseCommentId(2); + Timestamp timestamp = new Timestamp(System.currentTimeMillis()); + course1.setCoursePublishTime(timestamp); +// int result=courseMapper.releaseCourse(course1); +// if(result == 1){ +// System.out.println(result); +// }else{ +// System.out.println("error"); +// } + int n = courseMapper.releaseCourse(course1); + System.out.println(n); + + } + +// @Test +// public void deleteCourse() { +// CourseInfo course1 = new CourseInfo(); +// course1.setCourseId(2); +// course1.setCourseName("spring基础"); +// course1.setCourseType("后端基础类型"); +// course1.setCourseVideoUrl("192.6.1"); +// course1.setCourseDescribe("spring入门"); +// course1.setCourseViews("300"); +// course1.setUserId(2); +// course1.setCourseCommentId(2); +// Timestamp timestamp = new Timestamp(System.currentTimeMillis()); +// course1.setCoursePublishTime(timestamp); +// System.out.println(courseMapper.deleteCourse(course1)); +// } + + @Test + public void findAllCourseInfo() { + + List course = courseMapper.findAllCourseInfo(); + for (CourseInfo attribute : course){ + + System.out.println(attribute.getCourseId()); + System.out.println(attribute.getCourseName()); + System.out.println(attribute.getCourseType()); + System.out.println(attribute.getCourseVideoUrl()); + System.out.println(attribute.getCourseDescribe()); + System.out.println(attribute.getCourseViews()); + System.out.println(attribute.getUserId()); + System.out.println(attribute.getCourseCommentId()); + System.out.println(attribute.getCoursePublishTime()); + + } +// System.out.println(course.getCourseId()); +// System.out.println(course.getCourseName()); +// System.out.println(course.getCourseType()); +// System.out.println(course.getCourseVideoUrl()); +// System.out.println(course.getCourseDescribe()); +// System.out.println(course.getCourseViews()); +// System.out.println(course.getUserId()); +// System.out.println(course.getCourseCommentId()); +// System.out.println(course.getCoursePublishTime()); + } + + @Test + public void findAllCourseInfoByCourseType() { + + ListcourseInfoList = courseMapper.findAllCourseInfoByCourseType("后端基础课程"); + for (CourseInfo attribute : courseInfoList){ + + System.out.println(attribute.getCourseId()); + System.out.println(attribute.getCourseName()); + System.out.println(attribute.getCourseType()); + System.out.println(attribute.getCourseVideoUrl()); + System.out.println(attribute.getCourseDescribe()); + System.out.println(attribute.getCourseViews()); + System.out.println(attribute.getUserId()); + System.out.println(attribute.getCourseCommentId()); + System.out.println(attribute.getCoursePublishTime()); + + } + + + +// Iterator it = courseInfoList.iterator(); +// while(it.hasNext()){ +// System.out.println(it.next()); +// } + +// for( courseInfoList){ +//// System.out.println(course[n].getCourseId()); +//// System.out.println(course.getCourseName()); +//// System.out.println(course.getCourseType()); +//// System.out.println(course.getCourseVideoUrl()); +//// System.out.println(course.getCourseDescribe()); +//// System.out.println(course.getCourseViews()); +//// System.out.println(course.getUserId()); +//// System.out.println(course.getCourseCommentId()); +//// System.out.println(course.getCoursePublishTime()); +//// } + + + } +} \ No newline at end of file