diff --git a/pom.xml b/pom.xml
index 7bb0e289668f7545a90013d0455386354dcb8c45..c6f47ff0a6d275181e5168644418b57204196c3e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -137,6 +137,14 @@
spring-boot-starter-mail
+
+
+ org.springframework
+ spring-beans
+
+
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/src/main/java/com/letoy/study/controller/CourseController.java b/src/main/java/com/letoy/study/controller/CourseController.java
index 31cecef5b7132ba223468bbc4661195c6312aaa3..75e0035e8c57e2584fbe44a7f38ccfd95bee2f83 100644
--- a/src/main/java/com/letoy/study/controller/CourseController.java
+++ b/src/main/java/com/letoy/study/controller/CourseController.java
@@ -2,6 +2,7 @@ package com.letoy.study.controller;
import com.letoy.study.entity.CourseInfo;
import com.letoy.study.service.CourseService;
+import com.letoy.study.vo.CourseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -23,9 +24,9 @@ public class CourseController {
@PostMapping("/course/releaseCourse")
@ApiOperation(value = "发布课程信息", notes = "发布课程信息")
- public HashMap releaseCourse(CourseInfo courseInfo){
+ public HashMap releaseCourse(CourseVo courseVo){
- return courseService.releaseCourse(courseInfo);
+ return courseService.releaseCourse(courseVo);
}
@PostMapping("/course/deleteCourse")
diff --git a/src/main/java/com/letoy/study/entity/CourseInfo.java b/src/main/java/com/letoy/study/entity/CourseInfo.java
index fec36807f55206aaf7c55aa5ad26f9d767c97fca..cfb57385a3e1c7e8c99f7952443588ef1bec242a 100644
--- a/src/main/java/com/letoy/study/entity/CourseInfo.java
+++ b/src/main/java/com/letoy/study/entity/CourseInfo.java
@@ -32,5 +32,4 @@ public class CourseInfo {
@ApiModelProperty(value = "课程发布时间", example = "", dataType = "java.sql.Timestamp")
private java.sql.Timestamp coursePublishTime;
-
}
diff --git a/src/main/java/com/letoy/study/service/CourseService.java b/src/main/java/com/letoy/study/service/CourseService.java
index 8422bddf1f7d79a177c855cfba13641dbd5bd38c..3a142bc505668a0cb00bb9f4cbeb29e9a962fb26 100644
--- a/src/main/java/com/letoy/study/service/CourseService.java
+++ b/src/main/java/com/letoy/study/service/CourseService.java
@@ -1,6 +1,7 @@
package com.letoy.study.service;
import com.letoy.study.entity.CourseInfo;
+import com.letoy.study.vo.CourseVo;
import java.util.HashMap;
@@ -11,7 +12,7 @@ import java.util.HashMap;
*/
public interface CourseService {
- HashMap releaseCourse(CourseInfo courseInfo);
+ HashMap releaseCourse(CourseVo courseVo);
HashMap deleteCourse(CourseInfo courseInfo);
diff --git a/src/main/java/com/letoy/study/service/implement/CourseServiceImpl.java b/src/main/java/com/letoy/study/service/implement/CourseServiceImpl.java
index 94813cdbd561af4d199865c3e7bc5d99ec958d53..8a6181a2edce2b09f4d955849071161aa2fd8e8a 100644
--- a/src/main/java/com/letoy/study/service/implement/CourseServiceImpl.java
+++ b/src/main/java/com/letoy/study/service/implement/CourseServiceImpl.java
@@ -3,9 +3,13 @@ package com.letoy.study.service.implement;
import com.letoy.study.dao.CourseMapper;
import com.letoy.study.entity.CourseInfo;
import com.letoy.study.service.CourseService;
+import com.letoy.study.utils.ConvertUtils;
+import com.letoy.study.vo.CourseVo;
+import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
+import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
@@ -28,9 +32,23 @@ public class CourseServiceImpl implements CourseService {
@Override
- public HashMap releaseCourse(CourseInfo courseInfo) {
+ public HashMap releaseCourse(CourseVo courseVo) {
HashMap hashMap = new HashMap<>();
+
+ // 使用Spring BeanUtils拷贝Vo到新创建的courserInfo
+ CourseInfo courseInfo = new CourseInfo();
+ BeanUtils.copyProperties(courseVo, courseInfo);
+
+ // 使用工具类转换时间 将string转换为java.sql.timestamp
+ String coursePublishTime = courseVo.getCoursePublishTime();
+ Timestamp timestamp = ConvertUtils.strToSqlDate(coursePublishTime, "yyyy-MM-dd HH:mm:ss");
+ courseInfo.setCoursePublishTime(timestamp);
+
+
+ System.out.println(courseInfo);
+
+
int i = courseMapper.releaseCourse(courseInfo);
if (i == 0) {
hashMap.put("status", FAIL);
diff --git a/src/main/java/com/letoy/study/utils/ConvertUtils.java b/src/main/java/com/letoy/study/utils/ConvertUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..7dc9df14936ae63dfa241a475c5b92aab01a595e
--- /dev/null
+++ b/src/main/java/com/letoy/study/utils/ConvertUtils.java
@@ -0,0 +1,52 @@
+package com.letoy.study.utils;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+/**
+ * @program:letoy-study-java
+ * @author: WeiHaoL
+ * @Time: 2021/1/28 上午10:44
+ */
+
+// 用于各种变量的转化
+
+public class ConvertUtils {
+
+ /**
+ * 将java.sql.Timestamp对象转化为String字符串
+ * @param time
+ * 要格式的java.sql.Timestamp对象
+ * @param strFormat
+ * 输出的String字符串格式的限定(如:"yyyy-MM-dd HH:mm:ss")
+ * @return 表示日期的字符串
+ */
+ public static String dateToStr(java.sql.Timestamp time, String strFormat) {
+ DateFormat df = new SimpleDateFormat(strFormat);
+ String str = df.format(time);
+ return str;
+ }
+
+
+
+ /**
+ * 将String字符串转换为java.sql.Timestamp格式日期,用于数据库保存
+ * @param strDate
+ * 表示日期的字符串
+ * @param dateFormat
+ * 传入字符串的日期表示格式(如:"yyyy-MM-dd HH:mm:ss")
+ * @return java.sql.Timestamp类型日期对象(如果转换失败则返回null)
+ */
+ public static java.sql.Timestamp strToSqlDate(String strDate, String dateFormat) {
+ SimpleDateFormat sf = new SimpleDateFormat(dateFormat);
+ java.util.Date date = null;
+ try {
+ date = sf.parse(strDate);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ java.sql.Timestamp dateSQL = new java.sql.Timestamp(date.getTime());
+ return dateSQL;
+ }
+}
diff --git a/src/main/java/com/letoy/study/vo/CourseVo.java b/src/main/java/com/letoy/study/vo/CourseVo.java
new file mode 100644
index 0000000000000000000000000000000000000000..96b907430757b4523a06b00e2c3994a1f91260c9
--- /dev/null
+++ b/src/main/java/com/letoy/study/vo/CourseVo.java
@@ -0,0 +1,39 @@
+package com.letoy.study.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @program:letoy-study-java
+ * @author: WeiHaoL
+ * @Time: 2021/1/28 上午10:40
+ */
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CourseVo {
+
+
+ @ApiModelProperty(value = "课程ID", example = "1", dataType = "int")
+ private long courseId;
+ @ApiModelProperty(value = "课程名称", example = "Java入门", dataType = "String")
+ 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 = "yyyy-MM-dd HH:mm:ss", dataType = "String")
+ private String coursePublishTime;
+}