hyx 2 years ago
parent
commit
098689f246

+ 4 - 4
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/YxnnController.java

@@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.util.Map;
 
@@ -26,9 +25,10 @@ public class YxnnController {
 
     /**
      * 上传图片文件,并保存相应的信息
+     * required = false文件不是必传,防止未传文件导致报错
      */
     @PostMapping("/uploadDocumet")
-    public Map<String, Object> uploadDocument(@RequestParam("file") MultipartFile file, ImpressionNanan impressionNanan) {
+    public Map<String, Object> uploadDocument(@RequestParam(value = "file", required = false) MultipartFile file, ImpressionNanan impressionNanan) {
         try {
             return yxnnService.saveDocumetIn(file, impressionNanan);
         } catch (IOException e) {
@@ -43,7 +43,7 @@ public class YxnnController {
      * 通过条件查询多个图片,并赛选分页
      */
     @GetMapping("/getDocumentPage")
-    public Map<String, Object> getDocumentPage(HttpServletRequest request,int page, int limit, String pictureType, String examineState) {
+    public Map<String, Object> getDocumentPage(int page, int limit, String pictureType, String examineState) {
         try {
             if (Blank.isNotEmpty(page) && Blank.isNotEmpty(limit) && page > 0 && limit > 0) {
                 return SendUtil.send(true, null, yxnnService.getDocumentPage(page, limit, pictureType, examineState));
@@ -75,7 +75,7 @@ public class YxnnController {
      * 保存修改的信息
      */
     @PostMapping("updateDocumentById")
-    public Map<String, Object> updateDocumentById(@RequestParam("file") MultipartFile file, ImpressionNanan impressionNanan) {
+    public Map<String, Object> updateDocumentById(@RequestParam(value = "file", required = false) MultipartFile file, ImpressionNanan impressionNanan) {
         try {
             if (Blank.isEmpty(impressionNanan.getId())) {
                 return SendUtil.send(false, "", "id为空");

+ 9 - 6
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/YxnnServiceImpl.java

@@ -55,6 +55,9 @@ public class YxnnServiceImpl implements YxnnService {
         if (!Validator.isMobile(impressionNanan.getUploaderPhone())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "电话格式不正确,请填入移动电话号码");
         }
+        if (Blank.isEmpty(file)) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "文件不能为空");
+        }
         if (Blank.isEmpty(impressionNanan.getPictureTitle())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "标题不能为空");
         }
@@ -64,8 +67,8 @@ public class YxnnServiceImpl implements YxnnService {
         if (Blank.isEmpty(impressionNanan.getPictureAuthor())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");
         }
-        if (impressionNanan.getPictureAuthor().length() > 50) {
-            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于50");
+        if (impressionNanan.getPictureAuthor().length() > 10) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于10");
         }
         if (Blank.isEmpty(impressionNanan.getPictureDescription())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");
@@ -132,8 +135,8 @@ public class YxnnServiceImpl implements YxnnService {
         if (Blank.isEmpty(impressionNanan.getPictureAuthor())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");
         }
-        if (impressionNanan.getPictureAuthor().length() > 50) {
-            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于50");
+        if (impressionNanan.getPictureAuthor().length() > 10) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于10");
         }
         if (Blank.isEmpty(impressionNanan.getPictureDescription())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");
@@ -180,8 +183,8 @@ public class YxnnServiceImpl implements YxnnService {
         if (Blank.isEmpty(impressionNanan.getPictureAuthor())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");
         }
-        if (impressionNanan.getPictureAuthor().length() > 50) {
-            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于50");
+        if (impressionNanan.getPictureAuthor().length() > 10) {
+            return SendUtil.send(false, ConstStr.ADD_FAILED, "作者长度不能大于10");
         }
         if (Blank.isEmpty(impressionNanan.getPictureDescription())) {
             return SendUtil.send(false, ConstStr.ADD_FAILED, "作者不能为空");